Class: CPUExtension::CPUGov

Inherits:
Object
  • Object
show all
Defined in:
ext/distem/cpugov/cpugov.c

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Object) initialize



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'ext/distem/cpugov/cpugov.c', line 24

static VALUE cpugov_init(
  VALUE self,
  VALUE cores,
  VALUE freqmax,
  VALUE cgroup_path
)
{
	rb_iv_set(self, "@pitch", rb_float_new(DEFAULT_PITCH));
	rb_iv_set(self, "@cores", rb_ary_dup(cores));
	rb_iv_set(self, "@freqmax", freqmax);
	rb_iv_set(self, "@pid", INT2NUM(0));
	rb_iv_set(self, "@cgrouppath", rb_str_dup(cgroup_path));

  freq_max = freqmax;

	return self;
}

Instance Attribute Details

- (Object) cgrouppath (readonly)

- (Object) cores (readonly)

- (Object) freqmax (readonly)

- (Object) pid (readonly)

- (Object) pitch

Instance Method Details

- (Object) run



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'ext/distem/cpugov/cpugov.c', line 42

static VALUE cpugov_run(
  VALUE self,
  VALUE low_freq,
  VALUE high_freq,
  VALUE low_rate
)
{
  int pid;

  pid = fork();
  if (pid < 0)
    rb_raise(rb_eRuntimeError,"fork");
  if (!pid)
    {
      if (setsid() < 0)
	rb_raise(rb_eRuntimeError,"setsid");
      close(STDIN_FILENO);
      close(STDOUT_FILENO);
      close(STDERR_FILENO);

      rb_iterate(rb_each, rb_iv_get(self,"@cores"), cpugov_parse_core, Qnil);

      extrun(
	     (unsigned long long) (NUM2DBL(rb_iv_get(self, "@pitch")) * 1000000),
	     NUM2INT(low_freq),NUM2INT(high_freq),NUM2DBL(low_rate),
	     STR2CSTR(rb_iv_get(self,"@cgrouppath"))
	     );
      exit(0);
    }
  else
    rb_iv_set(self, "@pid", INT2NUM(pid));

  return Qnil;
}

- (Boolean) running?

Returns:

  • (Boolean)


90
91
92
93
94
95
96
# File 'ext/distem/cpugov/cpugov.c', line 90

static VALUE cpugov_is_run(VALUE self)
{
	if (NUM2INT(rb_iv_get(self, "@pid")))
		return Qtrue;
	else
		return Qfalse;
}

- (Object) stop



77
78
79
80
81
82
83
84
85
86
87
88
# File 'ext/distem/cpugov/cpugov.c', line 77

static VALUE cpugov_stop(VALUE self)
{
	int pid;

	pid = NUM2INT(rb_iv_get(self, "@pid"));
	kill(pid,SIGKILL);
  waitpid(pid,NULL,0);

	rb_iv_set(self, "@pid", INT2NUM(0));

	return Qnil;
}