Home | History | Annotate | Download | only in libcutils
      1 /*
      2 ** Copyright 2007, The Android Open Source Project
      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 
     17 #include <errno.h>
     18 #include <fcntl.h>
     19 #include <stdio.h>
     20 #include <stdlib.h>
     21 #include <string.h>
     22 #include <unistd.h>
     23 
     24 #include <cutils/iosched_policy.h>
     25 
     26 #if defined(__ANDROID__)
     27 #include <linux/ioprio.h>
     28 #include <sys/syscall.h>
     29 #define __android_unused
     30 #else
     31 #define __android_unused __attribute__((__unused__))
     32 #endif
     33 
     34 int android_set_ioprio(int pid __android_unused, IoSchedClass clazz __android_unused, int ioprio __android_unused) {
     35 #if defined(__ANDROID__)
     36     if (syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, pid, ioprio | (clazz << IOPRIO_CLASS_SHIFT))) {
     37         return -1;
     38     }
     39 #endif
     40     return 0;
     41 }
     42 
     43 int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *ioprio) {
     44 #if defined(__ANDROID__)
     45     int rc;
     46 
     47     if ((rc = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, pid)) < 0) {
     48         return -1;
     49     }
     50 
     51     *clazz = (rc >> IOPRIO_CLASS_SHIFT);
     52     *ioprio = (rc & 0xff);
     53 #else
     54     *clazz = IoSchedClass_NONE;
     55     *ioprio = 0;
     56 #endif
     57     return 0;
     58 }
     59