blob: f350f58b9f96df2fbb0182ec48765b28908844ff [file] [log] [blame]
San Mehat10d469b2010-02-25 14:02:55 -08001
2/* libs/cutils/iosched_policy.c
3**
4** Copyright 2007, The Android Open Source Project
5**
6** Licensed under the Apache License, Version 2.0 (the "License");
7** you may not use this file except in compliance with the License.
8** You may obtain a copy of the License at
9**
10** http://www.apache.org/licenses/LICENSE-2.0
11**
12** Unless required by applicable law or agreed to in writing, software
13** distributed under the License is distributed on an "AS IS" BASIS,
14** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15** See the License for the specific language governing permissions and
16** limitations under the License.
17*/
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <unistd.h>
22#include <string.h>
23#include <errno.h>
24#include <fcntl.h>
San Mehat10d469b2010-02-25 14:02:55 -080025
26#ifdef HAVE_SCHED_H
27
28#include <cutils/iosched_policy.h>
29
30extern int ioprio_set(int which, int who, int ioprio);
31
32enum {
33 WHO_PROCESS = 1,
34 WHO_PGRP,
35 WHO_USER,
36};
37
38#define CLASS_SHIFT 13
39#define IOPRIO_NORM 4
40
41int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio) {
San Mehate2fe2612010-02-26 10:57:17 -080042#ifdef HAVE_ANDROID_OS
San Mehat10d469b2010-02-25 14:02:55 -080043 if (ioprio_set(WHO_PROCESS, pid, ioprio | (clazz << CLASS_SHIFT))) {
44 return -1;
45 }
San Mehate2fe2612010-02-26 10:57:17 -080046#endif
San Mehat10d469b2010-02-25 14:02:55 -080047 return 0;
48}
49
50int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio) {
San Mehate2fe2612010-02-26 10:57:17 -080051#ifdef HAVE_ANDROID_OS
San Mehat10d469b2010-02-25 14:02:55 -080052 int rc;
53
54 if ((rc = ioprio_get(WHO_PROCESS, pid)) < 0) {
55 return -1;
56 }
57
58 *clazz = (rc >> CLASS_SHIFT);
59 *ioprio = (rc & 0xff);
San Mehate2fe2612010-02-26 10:57:17 -080060#else
61 *clazz = IoSchedClass_NONE;
62 *ioprio = 0;
63#endif
San Mehat10d469b2010-02-25 14:02:55 -080064 return 0;
65}
66
67#endif /* HAVE_SCHED_H */