blob: 3e80cb2873b4af3fc6962e1c8a440e5999c8291d [file] [log] [blame]
Mark Salyzyn3bca6062014-01-10 15:37:50 -08001/*
Mark Salyzyn3bca6062014-01-10 15:37:50 -08002** Copyright 2007-2014, The Android Open Source Project
San Mehat10d469b2010-02-25 14:02:55 -08003**
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 Mehat10d469b2010-02-25 14:02:55 -080017#include <errno.h>
18#include <fcntl.h>
Mark Salyzyn12717162014-04-29 15:49:14 -070019#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
Dan Albert167c0ed2014-06-12 17:53:03 -070022#include <sys/syscall.h>
Mark Salyzyn12717162014-04-29 15:49:14 -070023#include <unistd.h>
San Mehat10d469b2010-02-25 14:02:55 -080024
San Mehat10d469b2010-02-25 14:02:55 -080025#include <cutils/iosched_policy.h>
26
Mark Salyzyn3bca6062014-01-10 15:37:50 -080027#ifdef HAVE_ANDROID_OS
Dan Albert167c0ed2014-06-12 17:53:03 -070028#include <linux/ioprio.h>
Mark Salyzyn12717162014-04-29 15:49:14 -070029#define __android_unused
30#else
31#define __android_unused __attribute__((__unused__))
Mark Salyzyn3bca6062014-01-10 15:37:50 -080032#endif
San Mehat10d469b2010-02-25 14:02:55 -080033
Mark Salyzyn12717162014-04-29 15:49:14 -070034int android_set_ioprio(int pid __android_unused, IoSchedClass clazz __android_unused, int ioprio __android_unused) {
San Mehate2fe2612010-02-26 10:57:17 -080035#ifdef HAVE_ANDROID_OS
Dan Albert167c0ed2014-06-12 17:53:03 -070036 if (syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, pid, ioprio | (clazz << IOPRIO_CLASS_SHIFT))) {
San Mehat10d469b2010-02-25 14:02:55 -080037 return -1;
38 }
San Mehate2fe2612010-02-26 10:57:17 -080039#endif
San Mehat10d469b2010-02-25 14:02:55 -080040 return 0;
41}
42
Mark Salyzyn12717162014-04-29 15:49:14 -070043int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *ioprio) {
San Mehate2fe2612010-02-26 10:57:17 -080044#ifdef HAVE_ANDROID_OS
San Mehat10d469b2010-02-25 14:02:55 -080045 int rc;
46
Dan Albert167c0ed2014-06-12 17:53:03 -070047 if ((rc = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, pid)) < 0) {
San Mehat10d469b2010-02-25 14:02:55 -080048 return -1;
49 }
50
Dan Albert167c0ed2014-06-12 17:53:03 -070051 *clazz = (rc >> IOPRIO_CLASS_SHIFT);
San Mehat10d469b2010-02-25 14:02:55 -080052 *ioprio = (rc & 0xff);
San Mehate2fe2612010-02-26 10:57:17 -080053#else
54 *clazz = IoSchedClass_NONE;
55 *ioprio = 0;
56#endif
San Mehat10d469b2010-02-25 14:02:55 -080057 return 0;
58}