Merge change 3725 into donut
* changes: process: Clean up cgroup management
This commit is contained in:
@@ -50,7 +50,7 @@ pid_t gettid() { return syscall(__NR_gettid);}
|
|||||||
#undef __KERNEL__
|
#undef __KERNEL__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ENABLE_CGROUP_ERR_LOGGING 0
|
#define ENABLE_CGROUP_DEBUG 0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* List of cgroup names which map to ANDROID_TGROUP_ values in Thread.h
|
* List of cgroup names which map to ANDROID_TGROUP_ values in Thread.h
|
||||||
@@ -198,35 +198,39 @@ jint android_os_Process_getGidForName(JNIEnv* env, jobject clazz, jstring name)
|
|||||||
|
|
||||||
static int add_pid_to_cgroup(int pid, int grp)
|
static int add_pid_to_cgroup(int pid, int grp)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
int fd;
|
||||||
char path[255];
|
char path[255];
|
||||||
int rc;
|
char text[64];
|
||||||
|
|
||||||
sprintf(path, "/dev/cpuctl/%s/tasks", (cgroup_names[grp] ? cgroup_names[grp] : ""));
|
sprintf(path, "/dev/cpuctl/%s/tasks",
|
||||||
|
(cgroup_names[grp] ? cgroup_names[grp] : ""));
|
||||||
|
|
||||||
if (!(fp = fopen(path, "w"))) {
|
if ((fd = open(path, O_WRONLY)) < 0) {
|
||||||
#if ENABLE_CGROUP_ERR_LOGGING
|
LOGE("Error opening '%s' (%s)", path, strerror(errno));
|
||||||
LOGW("Unable to open %s (%s)\n", path, strerror(errno));
|
return -1;
|
||||||
#endif
|
|
||||||
return -errno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = fprintf(fp, "%d", pid);
|
sprintf(text, "%d", pid);
|
||||||
fclose(fp);
|
if (write(fd, text, strlen(text)) < 0) {
|
||||||
|
LOGE("Error writing to '%s' (%s)", path, strerror(errno));
|
||||||
if (rc < 0) {
|
close(fd);
|
||||||
#if ENABLE_CGROUP_ERR_LOGGING
|
return -1;
|
||||||
LOGW("Unable to move pid %d to cgroup %s (%s)\n", pid,
|
|
||||||
(cgroup_names[grp] ? cgroup_names[grp] : "<default>"),
|
|
||||||
strerror(errno));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (rc < 0) ? errno : 0;
|
close(fd);
|
||||||
|
|
||||||
|
#if ENABLE_CGROUP_DEBUG
|
||||||
|
LOGD("Pid %d sucessfully added to '%s'", pid, path);
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void android_os_Process_setThreadGroup(JNIEnv* env, jobject clazz, int pid, jint grp)
|
void android_os_Process_setThreadGroup(JNIEnv* env, jobject clazz, int pid, jint grp)
|
||||||
{
|
{
|
||||||
|
#if ENABLE_CGROUP_DEBUG
|
||||||
|
LOGD("android_os_Process_setThreadGroup(%d, %d)", pid, grp);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (grp > ANDROID_TGROUP_MAX || grp < 0) {
|
if (grp > ANDROID_TGROUP_MAX || grp < 0) {
|
||||||
signalExceptionForGroupError(env, clazz, EINVAL);
|
signalExceptionForGroupError(env, clazz, EINVAL);
|
||||||
return;
|
return;
|
||||||
@@ -243,6 +247,10 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin
|
|||||||
char proc_path[255];
|
char proc_path[255];
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
|
|
||||||
|
#if ENABLE_CGROUP_DEBUG
|
||||||
|
LOGD("android_os_Process_setProcessGroup(%d, %d)", pid, grp);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (grp > ANDROID_TGROUP_MAX || grp < 0) {
|
if (grp > ANDROID_TGROUP_MAX || grp < 0) {
|
||||||
signalExceptionForGroupError(env, clazz, EINVAL);
|
signalExceptionForGroupError(env, clazz, EINVAL);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user