CPU Hotplug를 지원하는 배터리 세이버가 없나요?

frech의 이미지

외장그래픽이 달린 노트북을 쓰는데 bumblebee로 외장 그래픽을 쓰고요, laptop-mode-tools나 tlp를 사용하면 wayland 환경 아래에서 자동으로 외장그래픽을 지원하는 프로그램이 외장그래픽을 사용해서 제가 직접 꺼줘야 하는 불편함이 생겨서 사용에 어려움이 있어서 사용을 못하고 있습니다.
위에 두 프로그램을 못 쓰다 보니까 배터리가 살살 녹아서 cpu덜 돌리면 배터리 적게 든다는 것 밖에 몰라 cpu hotplug를 하는 데몬을 만들어 쓰고 있습니다.
혹시 cpu hotplug를 지원하는 데몬이나 위에 배터리 세이버 말고 다른 프로그램은 알고 계신게 없는지 궁금합니다.

그리고 cpu hotplug를 파일 시스템을 통해서 말고 C api로 되어 있는게 없는지도 궁금합니다. 인터넷에는 잘 나오지 않네요.

#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/fs.h>
#include <sys/sysinfo.h>
 
void hotplug_cpu(unsigned short id, unsigned short check) { //id번 시피유 끄기
	char* status;
	if (check == 0 ) status = "0";
	else status = "1";
 
	char cpu[36];
	sprintf(cpu, "/sys/devices/system/cpu/cpu%d/online", id);
	int fd = open(cpu, O_RDWR );
 
	if (!write(fd, status, 2)) printf("failed to turn on/off cpu%d\n", id);
 
	close (fd);
}
 
void turbo_controller(unsigned short check) { //터보 부스트 제어
	char* status;
	if (check == 0) status = "1";
	else status = "0";
 
	int fd = open("/sys/devices/system/cpu/intel_pstate/no_turbo", O_RDWR);
 
	if (!write(fd, status, 2)) printf("failed to turn on/off turbo boost\n");
 
	close(fd);
}
 
int main(void) {
 
	pid_t pid;
	int i;
 
	pid = fork();
	if (pid == -1) {
		printf("fork\n");
		return -1;
	}
 
	if (pid != 0) exit(EXIT_SUCCESS);
 
	if (setsid() == -1) return -1;
 
	open("/dev/null", O_RDWR);
	dup(0);
	dup(0);
 
	unsigned short cpus = get_nprocs_conf();
	unsigned short energy_model = cpus / 3;
	unsigned short balance_model = 2 * energy_model;
 
	FILE* fp;
	int user, nice, system, idle, iowait, irq, softirq;
	int sum;
	float usage;
 
	unsigned short state = 0; // 0 energy safe model, 1 balanced model, 2 performance balanced model 3 performance mode
 
	fp = fopen("/proc/stat", "r");
        if (fp == NULL) {
        	printf ("failed to get stat\n");
        	exit(1);
        }
        fscanf(fp, "cpu  %d %d %d %d %d %d %d", &user, &nice, &system, &idle, &iowait, &irq, &softirq);
        fclose(fp);
 
	sleep(1);
 
	while(1) {
		int current_user;
		int current_system;
		fp = fopen("/proc/stat", "r");
		if (fp == NULL) {
			printf ("failed to get stat\n");
			exit(1);
		}
		fscanf(fp, "cpu  %d %d %d %d %d %d %d", &current_user, &nice, &current_system, &idle, &iowait, &irq, &softirq);
                fclose(fp);
		int current_sum = current_user + nice + system + idle + iowait + irq + softirq;
		int user_res = current_user - user;
		int system_res = current_system - system;
		int current_state;
		usage = (float)(user_res + system_res)/(current_sum - sum)*100;
		if ( usage < 5 ) { // 사용률 퍼센트로 계산해서 제어
			current_state = 0;	
		} else if (usage < 20 ) {
			current_state = 1;
		} else if (usage < 50 ) {
			current_state = 2;
		} else current_state = 3;
 
		if (current_state != state) {
 
			if (current_state == 0) {
				for ( int i = cpus-1;i > energy_model-1;i--) {
					hotplug_cpu(i + 6, 0);
					hotplug_cpu(i, 0);
				}
				turbo_controller(0);
			} else if (current_state == 1) {
				for ( int i = cpus-1;i > balance_model-1;i--) {
					hotplug_cpu(i + 6, 0);
					hotplug_cpu(i, 0);
				}
				for ( int i = balance_model-1;i > energy_model-1;i--) {
					hotplug_cpu(i, 1);
					hotplug_cpu(i + 6, 1);
				}
				turbo_controller(0);
			} else if (current_state == 2) {
				for ( int i = cpus-1;i > balance_model-1;i--) {
                                        hotplug_cpu(i + 6, 0);
                                        hotplug_cpu(i, 0);
                                }
                                for ( int i = balance_model-1;i > energy_model-1;i--) {
                                        hotplug_cpu(i, 1);
                                        hotplug_cpu(i + 6, 1);
                                }
                                turbo_controller(1);
			} else  {
				for (int i = cpus-1;i > 1;i--) {
					hotplug_cpu(i, 1);
					hotplug_cpu(i + 6, 1);
				}
				turbo_controller(1);
			}
 
			state = current_state;
 
		};
 
		sum = current_sum;
		user = current_user;
		system = current_system;
 
		sleep(1);
	}
 
	return 0;
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.