[go: up one dir, main page]

File: irqbalance.c

package info (click to toggle)
irqbalance 0.12-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 160 kB
  • ctags: 54
  • sloc: ansic: 491; sh: 94; xml: 31; makefile: 10
file content (106 lines) | stat: -rw-r--r-- 2,792 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>

/*
   Copyright (C) 2003 Red Hat, Inc. All rights reserved.
                                                                                                             
   Usage and distribution of this file are subject to the Open Software License version 2.1
   that can be found at http://www.opensource.org/licenses/osl-2.1.txt and the COPYING file as
   distributed together with this file is included herein by reference. Alternatively you can use 
   and distribute this file under version 1.1 of the same license.
                                                                                                                      
   Authors: Arjan van de Ven   <arjanv@redhat.com>
            Eric Dorland       <eric@debian.org>
*/

#include "prototypes.h"

int irq_cost[MAX_CPU];		/* cummulative assigned irq's already */
int this_type[MAX_CPU];		/* number of irq's already assigned within this class */

struct irqdescriptor interrupts[MAX_INTERRUPTS];


int rotate_premium = 12500;

void term_signal(int signal)
{
    unlink("/var/run/irqbalance.pid");
    exit(EXIT_SUCCESS);
}

void commandpolicy(char *pol, int phase)
{
	/* Allow --noethernet */
	if (!strcmp("--noethernet",pol)) {
		class_policy[IRQ_ETH] = POLICY_IGNORE;
		class_policy[IRQ_GIGE] = POLICY_IGNORE;
		if (phase>0) {
			class_policy[IRQ_OTHER] = POLICY_ROTATE;
			class_policy[IRQ_LEGACY] = POLICY_ROTATE;
			class_policy[IRQ_SCSI] = POLICY_ROTATE;
			class_policy[IRQ_TIMER] = POLICY_ROTATE;
		}
	}

}


int main(int argc, char **argv)
{
    FILE *pid_file;
    int 
	
	class_policy[IRQ_TIMER] = POLICY_ROTATE;
	
	parse_proc_cpuinfo();
	
	/* Allow --oneshot as option to force a once only setting of the affinity and then exit */
	if ((argc>1) &&  (!strcmp("--oneshot",argv[1])))
		

	if (argc>1) 		
		commandpolicy(argv[1], 0);
	
	if (cpucount < 2) 
		exit(EXIT_SUCCESS); /* UP balancing is useless */
		
	/* in oneshot mode, don't do anything except on pIV boxes */
	if (oneshot && (machineneedsbalance!=15))
		exit(EXIT_SUCCESS);
	parse_proc_interrupts(0); 

#ifndef DEBUG
	pid_file = fopen("/var/run/irqbalance.pid", "w");
	if (pid_file == NULL)
        exit(EXIT_FAILURE);
    daemon(0,0);
    signal(SIGTERM, term_signal);
    fprintf(pid_file, "%d\n", getpid());
    fclose(pid_file);
    
#endif
	/* 
	 * Allow 5 seconds for gathering irq counts before the first balance; 60 in case of one-shot
	 * balancing 
	 */
	sleep(5 + 55*oneshot);  
	while (1) {
		parse_proc_interrupts(1); 
		balance_policy();
		activate_irqtable();
		if (argc>1)
			commandpolicy(argv[1], 1);

#ifdef DEBUG
		dump_settings();
#endif
		if (oneshot)
			break;
		sleep(10);
	}
	return EXIT_SUCCESS;
}