iosched_policy.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include <cutils/iosched_policy.h>
  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. #if defined(__ANDROID__)
  24. #define IOPRIO_WHO_PROCESS (1)
  25. #define IOPRIO_CLASS_SHIFT (13)
  26. #include <sys/syscall.h>
  27. #define __android_unused
  28. #else
  29. #define __android_unused __attribute__((__unused__))
  30. #endif
  31. int android_set_ioprio(int pid __android_unused, IoSchedClass clazz __android_unused, int ioprio __android_unused) {
  32. #if defined(__ANDROID__)
  33. if (syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, pid, ioprio | (clazz << IOPRIO_CLASS_SHIFT))) {
  34. return -1;
  35. }
  36. #endif
  37. return 0;
  38. }
  39. int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *ioprio) {
  40. #if defined(__ANDROID__)
  41. int rc;
  42. if ((rc = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, pid)) < 0) {
  43. return -1;
  44. }
  45. *clazz = static_cast<IoSchedClass>(rc >> IOPRIO_CLASS_SHIFT);
  46. *ioprio = (rc & 0xff);
  47. #else
  48. *clazz = IoSchedClass_NONE;
  49. *ioprio = 0;
  50. #endif
  51. return 0;
  52. }