chenke
2017-08-04 b1cddf6feb397c495546c153987a1a337fb01409
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "cpu_sched_test.h"
 
#include <logger.h>
 
#include<sched.h>
#include<ctype.h>
#include<sys/types.h>
#include<sys/sysinfo.h>
#include<unistd.h>
 
// setup the cpu set of this program (task) to run on
void set_task_cpu(int id)
{
    int num = sysconf(_SC_NPROCESSORS_CONF);
 
    cpu_set_t mask;
    CPU_ZERO(&mask);
    if (sched_getaffinity(0, sizeof(mask), &mask) == -1)
    {
        fprintf(stderr, "warning: could not get CPU affinity/n");
    }
 
    for(int i= 0; i< num; i++)
    {
        LOG_ERROR << "cpu " << i <<": " << CPU_ISSET(i, &mask) <<LOG_ENDL;
    }
 
    //CPU_CLR(0x0000, &mask);
    //CPU_CLR(0x0001, &mask);
    //CPU_CLR(0x0002, &mask);
    //CPU_CLR(0x0003, &mask);
    //CPU_CLR(0x0004, &mask);
    //CPU_CLR(0x0005, &mask);
 
    CPU_SET(0x0000, &mask);
    CPU_SET(0x0001, &mask);
    CPU_SET(0x0002, &mask);
    CPU_SET(0x0003, &mask);
    CPU_SET(0x0004, &mask);
    CPU_SET(0x0005, &mask);
 
    if (sched_setaffinity(0, sizeof(mask), &mask) == -1)
    {
        LOG_ERROR << "warning: could not set CPU affinity" << LOG_ENDL;
    }
 
    for(int i= 0; i< num; i++)
    {
        LOG_ERROR << "cpu " << i <<": " << CPU_ISSET(i, &mask) <<LOG_ENDL;
    }
}
 
void cpu_sched()
{
    //set_task_cpu(0x0003);
}
 
void pthread_cpu_sched(const pthread_attr_t *attr)
{
    cpu_set_t mask;
    CPU_ZERO(&mask);
 
}