Signed-of by pradeep k surisetty < psuri...@linux.vnet.ibm.com>
---
diff -uprN hardlimitd/cg_util.c hardlimitd-new/cg_util.c
--- hardlimitd/cg_util.c        2011-03-02 01:38:02.000000000 -0500
+++ hardlimitd-new/cg_util.c    2011-03-08 17:32:01.113088001 -0500
@@ -158,6 +158,57 @@ void add_task_to_pcpu_cg(pid_t pid, int 
        set_notify_on_release(group);
 }
 
+void add_task_to_sys_daemon_cg(int cpuid)
+{
+        char group[FILENAME_MAX];
+        struct cgroup *cgroup;
+        int ret = -1;
+        pid_t pid,ppid;
+        FILE *pid_list,*ppid_file;
+        char command[512];
+
+        snprintf(group, FILENAME_MAX, "%s/%d", "libvirt/qemu/sys",cpuid );
+        cgroup = cgroup_new_cgroup(group);
+        if (cgroup == NULL) {
+                dprintf("cgroup allocation error %d\n", errno);
+                printf("group error\n");
+                return;
+        }
+        cgroup_add_controller(cgroup, "cpu");
+        cgroup_add_controller(cgroup, "cpuacct");
+        ret = cgroup_get_cgroup(cgroup);
+
+        if (ret < 0) {
+                dprintf("cgroup error %s\n", cgroup_strerror(ret));
+                printf("group error\n");
+        }
+        dprintf("\t\t\t\t\t%s, created group %s\n", __func__, group);
+
+        pid_list = fopen("/cgroup/cpu/tasks", "r");
+        if (pid_list == NULL) {
+                printf("file open failed\n");
+        }
+        while((pid = fgetc(pid_list))!=EOF)
+        {
+                fscanf(pid_list, "%d", &pid);
+                snprintf(command, sizeof(command), "ps -ef|awk -v p=%d 
'p==$2{print $3}'",pid);
+                ppid_file = popen(command,"r");
+                if (ppid_file==NULL) {
+                        printf("popen error");
+                }
+                fscanf(ppid_file, "%d", &ppid);
+                if(ppid != 2 && ppid != 0){
+                        pin_nonvm_pid_cpu(pid, 0);
+                        if ((ret = cgroup_attach_task_pid(cgroup,pid)) < 0) {
+                                dprintf("unable to add task to vcg %s\n", 
cgroup_strerror(ret));
+                        }
+                }
+                pclose(ppid_file);
+         }
+         fclose(pid_list);
+         cgroup_free(&cgroup);
+}
+
 void destroy_pcpu_cg(int cpuid)
 {
        char group[FILENAME_MAX];
@@ -247,6 +298,40 @@ out:
        cgroup_free(&cgroup);
 }
 
+void set_sys_daemon_share(int shares)
+{
+        char group[FILENAME_MAX];
+        struct cgroup *cgroup;
+        int ret = -1;
+        struct cgroup_controller *controller;
+
+        snprintf(group, FILENAME_MAX, "%s", "libvirt/qemu/system/");
+        cgroup = cgroup_new_cgroup(group);
+        if (cgroup == NULL) {
+                dprintf("cgroup allocation error %d\n", errno);
+                return;
+        }
+        controller = cgroup_add_controller(cgroup, "cpu");
+        if (controller == NULL) {
+                dprintf("cgroup error in getting CPU controller %s\n",
+                        cgroup_strerror(ret));
+                goto out;
+        }
+        ret = cgroup_set_value_uint64(controller, "cpu.shares", shares);
+        if (ret < 0) {
+                dprintf("cgroup shares set error %s\n", cgroup_strerror(ret));
+                goto out;
+        }
+        ret = cgroup_modify_cgroup(cgroup);
+        if (ret < 0) {
+                dprintf("cgroup shares set error %s\n", cgroup_strerror(ret));
+                goto out;
+        }
+        dprintf("%s, set vm share to %d for cgroup %s\n", __func__, shares, 
group);
+out:
+        cgroup_free(&cgroup);
+}
+
 void place_vcpu_in_separate_cg(struct vm *vm, int vcpu_tid)
 {
        char group[FILENAME_MAX];
diff -uprN hardlimitd/cg_util.h hardlimitd-new/cg_util.h
--- hardlimitd/cg_util.h        2011-02-23 22:26:45.000000000 -0500
+++ hardlimitd-new/cg_util.h    2011-03-09 13:52:58.349088002 -0500
@@ -11,15 +11,19 @@ enum thread_type {
 
 void add_task_to_vcpu_cg(pid_t pid, int vcpu_tid, char *vmname);
 void add_task_to_pcpu_cg (pid_t pid, int cpuid);
+void add_task_to_sys_daemon_cg(int cpuid);
 void set_pcpu_cg_share(int cpuid, int shares);
 void set_vm_cg_share(char *vmname, int shares);
 void set_vcpu_cg_share(char *vmname, int vcpu_tid, int shares);
+void set_sys_daemon_share(int shares);
 int find_vm_tasks(struct vm *vm, int **tasks);
 int create_account_groups(char *vm_name);
 void destroy_account_groups(char *vm_name);
 void add_task_to_accounting_group(char *vm_name, int tid, enum thread_type 
type);
 void place_vcpu_in_separate_cg(struct vm *vm, int vcpu_tid);
 void cleanup_vm_cgroups(char *vmname);
+void pin_nonvm_pid_cpu(pid_t, int cpuid);
+void process_sys_daemon_setup(int nonvm_cpu);
 
 
 #endif /* _CG_UTIL_H_ */
Binary files hardlimitd/.cg_util.h.swp and hardlimitd-new/.cg_util.h.swp differ
diff -uprN hardlimitd/daemon.c hardlimitd-new/daemon.c
--- hardlimitd/daemon.c 2011-03-02 21:04:49.000000000 -0500
+++ hardlimitd-new/daemon.c     2011-03-09 14:02:38.006088002 -0500
@@ -31,10 +31,15 @@
 int numcpus = 0;
 int pcpu_ccu = 1;
 int default_vcpu_ccu = 1;
+int nonvm_pcpu_ccu = 1;
 int machine_capacity_left = 0;
 int num_numa_nodes;
 int debug_mode;
 int daemon_mode = 1;
+static int diff_ccu_to_sys = 0;
+int diff_ccu = 0;
+int ccu_sys = 1;
+
 
 char *topo_filename;   /* topology config file name */
 char *vmtype_filename; /* VM-type config file */
@@ -49,7 +54,7 @@ struct cpuinfo *ci, *cit;
 static void usage(char *argv[])
 {
        printf("hardlimitd version %s \n", HLIMIT_VERSION);
-       printf("Usage : %s [-d[filename]] -c topology_config_file -m 
vmtype_config_file -f <filler path> -u per_cpu_ccu -v per_vpcu_ccu\n", argv[0]);
+       printf("Usage : %s [-d[filename]] -c topology_config_file -m 
vmtype_config_file -f <filler path> -u per_cpu_ccu -v per_vpcu_ccu -s 
ccu_sys\n", argv[0]);
        exit(1);
 }
 
@@ -98,7 +103,7 @@ void check_options(int argc, char **argv
        int opt;
 
        logfile = stdout;
-       while ((opt = getopt(argc, argv, "d::c:u:v:f:m:")) != -1) {
+       while ((opt = getopt(argc, argv, "d::c:u:v:f:m:s:")) != -1) {
                switch(opt) 
                {
                case 'd':
@@ -140,6 +145,11 @@ void check_options(int argc, char **argv
                        default_vcpu_ccu = atoi(optarg);
                        dprintf("Default CCU per VCPU = %d \n", 
default_vcpu_ccu);
                        break;
+                case 's':
+                        ccu_sys = atoi(optarg);
+                        dprintf("Non VM CCU = %d \n", ccu_sys);
+                        break;
+
                default:
                        usage(argv);
                }
@@ -226,7 +236,7 @@ static void populate_cores(struct core *
        struct package *pkgptr = cptr->package;
        struct node *nptr = pkgptr->node;
        struct cpu *cpuarr = NULL;
-       int oldid, j;
+       int oldid, j, reserve_cpu_capacity = 0;
        
        dprintf ("\t\tPopulating coreid: %d\n", cptr->id);
 
@@ -247,12 +257,46 @@ static void populate_cores(struct core *
                        cpu->id = ci->cpuid;
                        cpu->pid = 0;
                        cpu->num_vms = 0;
-                       cpu->left_cpu_capacity = pcpu_ccu;
+                        if(cpu->id ==0) {
+                                diff_ccu_to_sys = pcpu_ccu - ccu_sys;
+                                add_task_to_sys_daemon_cg(cpu->id);
+                                if(diff_ccu_to_sys > 0) {
+                                         cptr->left_cpu_capacity -=  ccu_sys;
+                                         cpu->left_cpu_capacity = 
diff_ccu_to_sys;
+                                        reserve_cpu_capacity = ccu_sys;
+                                         diff_ccu_to_sys = 0;
+                                } else {
+                                        cptr->left_cpu_capacity -=  pcpu_ccu;
+                                        cpu->left_cpu_capacity = 0;
+                                       reserve_cpu_capacity = pcpu_ccu;
+                                }       
+                         } else {
+                                if(diff_ccu_to_sys < 0 ) {
+                                        if(pcpu_ccu < -(diff_ccu_to_sys)) {
+                                                cptr->left_cpu_capacity -= 
pcpu_ccu;
+                                                cpu->left_cpu_capacity = 0;
+                                               reserve_cpu_capacity = pcpu_ccu;
+                                                diff_ccu_to_sys = pcpu_ccu + 
diff_ccu_to_sys;
+                                        } else {
+                                                cptr->left_cpu_capacity -= 
-(diff_ccu_to_sys);
+                                                cpu->left_cpu_capacity = 
pcpu_ccu + diff_ccu_to_sys;
+                                               reserve_cpu_capacity = 
-(diff_ccu_to_sys);
+                                                diff_ccu_to_sys = 0;
+                                                }
+                                } else {
+                                        cptr->left_cpu_capacity -= 
diff_ccu_to_sys;
+                                        cpu->left_cpu_capacity = pcpu_ccu;
+                                       reserve_cpu_capacity = 0;
+                                }
+                        } 
                        cpu->core = cptr;
                        oldid = ci->cpuid;
                        dprintf ("\t\t\tCPU ID: %d, capacity = %d\n", cpu->id, 
cpu->left_cpu_capacity);
                        cpu++;
                }
+                if(reserve_cpu_capacity !=0) {
+                        add_task_to_sys_daemon_cg(cpu->id);
+               }
        }
 
        dprintf ("\t\tCoreid: %d, Left CCU %d\n", cptr->id, 
cptr->left_cpu_capacity);
@@ -502,6 +546,7 @@ extern int get_cgroup_mount_point(void);
 
 static void run_daemon(void)
 {
+        process_sys_daemon_setup(ccu_sys);
        eventloop();
 }
 
@@ -586,7 +631,7 @@ static void parse_topology(int argc, cha
        struct node *nptr;
        int i, oldid;
 
-       if (!topo_filename || !fillerpath || !vmtype_filename || !pcpu_ccu || 
!default_vcpu_ccu || !logfile)
+       if (!topo_filename || !fillerpath || !vmtype_filename || !pcpu_ccu || 
!default_vcpu_ccu || !logfile|| !ccu_sys)
                usage(argv);
        
        fp = fopen(topo_filename, "r"); 
diff -uprN hardlimitd/packvm.c hardlimitd-new/packvm.c
--- hardlimitd/packvm.c 2011-03-02 21:04:49.000000000 -0500
+++ hardlimitd-new/packvm.c     2011-03-09 13:53:26.379088002 -0500
@@ -175,6 +175,16 @@ static int pin_vcpu(struct vm *vm, int v
        return rc;
 }
 
+void process_sys_daemon_setup(int nonvm_pid_share)
+{
+       set_sys_daemon_share( nonvm_pid_share*CCU_SCALE);
+}
+
+void pin_nonvm_pid_cpu(pid_t pid, int cpuid)
+{
+       set_affinity(pid, cpuid);
+}
+
 static void place_next_vcpu_on_pcpu(struct vm *vm, struct cpu *cpu)
 {
        struct core *core = cpu->core;
diff -uprN hardlimitd/README hardlimitd-new/README
--- hardlimitd/README   2011-02-27 02:39:17.000000000 -0500
+++ hardlimitd-new/README       2011-03-08 15:12:54.741088001 -0500
@@ -25,7 +25,7 @@ Steps to use hardlimit program
 
 - Launch hardlimitd program as:
 
-       # ./hardlimitd -ddebug -c ./machine_topo -m vmtype_config -f `pwd` -u N 
-v V
+       # ./hardlimitd -ddebug -c ./machine_topo -m vmtype_config -f `pwd` -u N 
-v V -s W
 
        -ddebug -> File to which debug information should be written to
        "./machine_top" -> File representing machine topology, which will
@@ -34,6 +34,7 @@ Steps to use hardlimit program
        V-> how many CCU (Cloud Compute Units) is virtual CPU worth by default?
            This value will be used when a VM's type is unknown or its vcpu_ccu
            can't be derived
+       W-> How many CCU for system daemons?
        "vmtype_config" -> File specifying VCPU CCU for various vm types.
 
    At any time hardlimitd can be asked to exit by:
---
_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to