iosched_policy.c revision 10d469bff9031e857c7a290dae7d6ccf7b3a18f8
1 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> 25#include <linux/unistd.h> 26 27#ifdef HAVE_SCHED_H 28 29#include <cutils/iosched_policy.h> 30 31extern int ioprio_set(int which, int who, int ioprio); 32 33enum { 34 WHO_PROCESS = 1, 35 WHO_PGRP, 36 WHO_USER, 37}; 38 39#define CLASS_SHIFT 13 40#define IOPRIO_NORM 4 41 42int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio) { 43 if (ioprio_set(WHO_PROCESS, pid, ioprio | (clazz << CLASS_SHIFT))) { 44 return -1; 45 } 46 return 0; 47} 48 49int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio) { 50 int rc; 51 52 if ((rc = ioprio_get(WHO_PROCESS, pid)) < 0) { 53 return -1; 54 } 55 56 *clazz = (rc >> CLASS_SHIFT); 57 *ioprio = (rc & 0xff); 58 return 0; 59} 60 61#endif /* HAVE_SCHED_H */ 62