Mark Salyzyn | 3bca606 | 2014-01-10 15:37:50 -0800 | [diff] [blame] | 1 | /* |
Elliott Hughes | af98efb | 2015-04-02 13:36:54 -0700 | [diff] [blame^] | 2 | ** Copyright 2007, The Android Open Source Project |
San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 3 | ** |
| 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | ** you may not use this file except in compliance with the License. |
| 6 | ** You may obtain a copy of the License at |
| 7 | ** |
| 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | ** |
| 10 | ** Unless required by applicable law or agreed to in writing, software |
| 11 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | ** See the License for the specific language governing permissions and |
| 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 17 | #include <errno.h> |
| 18 | #include <fcntl.h> |
Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
| 22 | #include <unistd.h> |
San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 23 | |
San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 24 | #include <cutils/iosched_policy.h> |
| 25 | |
Mark Salyzyn | 3bca606 | 2014-01-10 15:37:50 -0800 | [diff] [blame] | 26 | #ifdef HAVE_ANDROID_OS |
Dan Albert | 167c0ed | 2014-06-12 17:53:03 -0700 | [diff] [blame] | 27 | #include <linux/ioprio.h> |
Dan Albert | 5e541bf | 2014-06-12 21:06:58 -0700 | [diff] [blame] | 28 | #include <sys/syscall.h> |
Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 29 | #define __android_unused |
| 30 | #else |
| 31 | #define __android_unused __attribute__((__unused__)) |
Mark Salyzyn | 3bca606 | 2014-01-10 15:37:50 -0800 | [diff] [blame] | 32 | #endif |
San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 33 | |
Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 34 | int android_set_ioprio(int pid __android_unused, IoSchedClass clazz __android_unused, int ioprio __android_unused) { |
San Mehat | e2fe261 | 2010-02-26 10:57:17 -0800 | [diff] [blame] | 35 | #ifdef HAVE_ANDROID_OS |
Dan Albert | 167c0ed | 2014-06-12 17:53:03 -0700 | [diff] [blame] | 36 | if (syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, pid, ioprio | (clazz << IOPRIO_CLASS_SHIFT))) { |
San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 37 | return -1; |
| 38 | } |
San Mehat | e2fe261 | 2010-02-26 10:57:17 -0800 | [diff] [blame] | 39 | #endif |
San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 40 | return 0; |
| 41 | } |
| 42 | |
Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 43 | int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *ioprio) { |
San Mehat | e2fe261 | 2010-02-26 10:57:17 -0800 | [diff] [blame] | 44 | #ifdef HAVE_ANDROID_OS |
San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 45 | int rc; |
| 46 | |
Dan Albert | 167c0ed | 2014-06-12 17:53:03 -0700 | [diff] [blame] | 47 | if ((rc = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, pid)) < 0) { |
San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 48 | return -1; |
| 49 | } |
| 50 | |
Dan Albert | 167c0ed | 2014-06-12 17:53:03 -0700 | [diff] [blame] | 51 | *clazz = (rc >> IOPRIO_CLASS_SHIFT); |
San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 52 | *ioprio = (rc & 0xff); |
San Mehat | e2fe261 | 2010-02-26 10:57:17 -0800 | [diff] [blame] | 53 | #else |
| 54 | *clazz = IoSchedClass_NONE; |
| 55 | *ioprio = 0; |
| 56 | #endif |
San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 57 | return 0; |
| 58 | } |