Loading include/cutils/sched_policy.h +17 −0 Original line number Diff line number Diff line Loading @@ -24,11 +24,28 @@ extern "C" { typedef enum { SP_BACKGROUND = 0, SP_FOREGROUND = 1, SP_CNT, SP_MAX = SP_CNT - 1, } SchedPolicy; /* Assign thread tid to the cgroup associated with the specified policy. * If the thread is a thread group leader, that is it's gettid() == getpid(), * then the other threads in the same thread group are _not_ affected. * Return value: 0 for success, or -errno for error. */ extern int set_sched_policy(int tid, SchedPolicy policy); /* Return the policy associated with the cgroup of thread tid via policy pointer. * Return value: 0 for success, or -1 for error and set errno. */ extern int get_sched_policy(int tid, SchedPolicy *policy); /* Return a displayable string corresponding to policy. * Return value: non-NULL NUL-terminated name of unspecified length; * the caller is responsible for displaying the useful part of the string. */ extern const char *get_sched_policy_name(SchedPolicy policy); #ifdef __cplusplus } #endif Loading libcutils/sched_policy.c +12 −0 Original line number Diff line number Diff line Loading @@ -273,5 +273,17 @@ int set_sched_policy(int tid, SchedPolicy policy) return 0; } const char *get_sched_policy_name(SchedPolicy policy) { static const char * const strings[SP_CNT] = { [SP_BACKGROUND] = "bg", [SP_FOREGROUND] = "fg", }; if ((policy < SP_CNT) && (strings[policy] != NULL)) return strings[policy]; else return "error"; } #endif /* HAVE_PTHREADS */ #endif /* HAVE_SCHED_H */ toolbox/ps.c +2 −8 Original line number Diff line number Diff line Loading @@ -167,14 +167,8 @@ static int ps_line(int pid, int tid, char *namefilter) SchedPolicy p; if (get_sched_policy(pid, &p) < 0) printf(" un "); else { if (p == SP_BACKGROUND) printf(" bg "); else if (p == SP_FOREGROUND) printf(" fg "); else printf(" er "); } printf(" %.2s ", get_sched_policy_name(p)); } printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name); if(display_flags&SHOW_TIME) Loading toolbox/top.c +5 −8 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ struct cpu_info { #define PROC_NAME_LEN 64 #define THREAD_NAME_LEN 32 #define POLICY_NAME_LEN 4 struct proc_info { struct proc_info *next; Loading @@ -67,7 +68,7 @@ struct proc_info { long rss; int prs; int num_threads; char policy[32]; char policy[POLICY_NAME_LEN]; }; struct proc_list { Loading Loading @@ -381,14 +382,10 @@ static int read_cmdline(char *filename, struct proc_info *proc) { static void read_policy(int pid, struct proc_info *proc) { SchedPolicy p; if (get_sched_policy(pid, &p) < 0) strcpy(proc->policy, "unk"); strlcpy(proc->policy, "unk", POLICY_NAME_LEN); else { if (p == SP_BACKGROUND) strcpy(proc->policy, "bg"); else if (p == SP_FOREGROUND) strcpy(proc->policy, "fg"); else strcpy(proc->policy, "er"); strlcpy(proc->policy, get_sched_policy_name(p), POLICY_NAME_LEN); proc->policy[2] = '\0'; } } Loading Loading
include/cutils/sched_policy.h +17 −0 Original line number Diff line number Diff line Loading @@ -24,11 +24,28 @@ extern "C" { typedef enum { SP_BACKGROUND = 0, SP_FOREGROUND = 1, SP_CNT, SP_MAX = SP_CNT - 1, } SchedPolicy; /* Assign thread tid to the cgroup associated with the specified policy. * If the thread is a thread group leader, that is it's gettid() == getpid(), * then the other threads in the same thread group are _not_ affected. * Return value: 0 for success, or -errno for error. */ extern int set_sched_policy(int tid, SchedPolicy policy); /* Return the policy associated with the cgroup of thread tid via policy pointer. * Return value: 0 for success, or -1 for error and set errno. */ extern int get_sched_policy(int tid, SchedPolicy *policy); /* Return a displayable string corresponding to policy. * Return value: non-NULL NUL-terminated name of unspecified length; * the caller is responsible for displaying the useful part of the string. */ extern const char *get_sched_policy_name(SchedPolicy policy); #ifdef __cplusplus } #endif Loading
libcutils/sched_policy.c +12 −0 Original line number Diff line number Diff line Loading @@ -273,5 +273,17 @@ int set_sched_policy(int tid, SchedPolicy policy) return 0; } const char *get_sched_policy_name(SchedPolicy policy) { static const char * const strings[SP_CNT] = { [SP_BACKGROUND] = "bg", [SP_FOREGROUND] = "fg", }; if ((policy < SP_CNT) && (strings[policy] != NULL)) return strings[policy]; else return "error"; } #endif /* HAVE_PTHREADS */ #endif /* HAVE_SCHED_H */
toolbox/ps.c +2 −8 Original line number Diff line number Diff line Loading @@ -167,14 +167,8 @@ static int ps_line(int pid, int tid, char *namefilter) SchedPolicy p; if (get_sched_policy(pid, &p) < 0) printf(" un "); else { if (p == SP_BACKGROUND) printf(" bg "); else if (p == SP_FOREGROUND) printf(" fg "); else printf(" er "); } printf(" %.2s ", get_sched_policy_name(p)); } printf(" %08x %08x %s %s", wchan, eip, state, cmdline[0] ? cmdline : name); if(display_flags&SHOW_TIME) Loading
toolbox/top.c +5 −8 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ struct cpu_info { #define PROC_NAME_LEN 64 #define THREAD_NAME_LEN 32 #define POLICY_NAME_LEN 4 struct proc_info { struct proc_info *next; Loading @@ -67,7 +68,7 @@ struct proc_info { long rss; int prs; int num_threads; char policy[32]; char policy[POLICY_NAME_LEN]; }; struct proc_list { Loading Loading @@ -381,14 +382,10 @@ static int read_cmdline(char *filename, struct proc_info *proc) { static void read_policy(int pid, struct proc_info *proc) { SchedPolicy p; if (get_sched_policy(pid, &p) < 0) strcpy(proc->policy, "unk"); strlcpy(proc->policy, "unk", POLICY_NAME_LEN); else { if (p == SP_BACKGROUND) strcpy(proc->policy, "bg"); else if (p == SP_FOREGROUND) strcpy(proc->policy, "fg"); else strcpy(proc->policy, "er"); strlcpy(proc->policy, get_sched_policy_name(p), POLICY_NAME_LEN); proc->policy[2] = '\0'; } } Loading