summaryrefslogtreecommitdiffstats
path: root/src/process/interrupt.cpp
blob: a6553b1a2fb23938f1b204151c54f691c34192cd (plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * Copyright 2010, Intel Corporation
 *
 * This file is part of PowerTOP
 *
 * This program file is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program in a file named COPYING; if not, write to the
 * Free Software Foundation, Inc,
 * 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA
 * or just google for it.
 *
 * Authors:
 *	Arjan van de Ven <arjan@linux.intel.com>
 */
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "process.h"
#include "interrupt.h"
#include "../lib.h"

const char* softirqs[] = {
	"HI_SOFTIRQ",
	"timer(softirq)",
	"net tx(softirq)",
	"net_rx(softirq)",
	"block(softirq)",
	"block_iopoll(softirq)",
	"tasklet(softirq)",
	"sched(softirq)",
	"hrtimer(softirq)",
	"RCU(softirq)",
	NULL
};


interrupt::interrupt(const char *_handler, int _number) : power_consumer()
{
	char buf[128];
	running_since = 0;
	number = _number;
	pt_strcpy(handler, _handler);
	raw_count = 0;
	snprintf(desc, sizeof(desc), "[%i] %s", number, pretty_print(handler, buf, 128));
}


vector <class interrupt *> all_interrupts;

void interrupt::start_interrupt(uint64_t time)
{
	running_since = time;
	raw_count ++;
}

uint64_t interrupt::end_interrupt(uint64_t time)
{
	uint64_t delta;

	delta = time - running_since;
	accumulated_runtime += delta;
	return delta;
}

const char * interrupt::description(void)
{
	if (child_runtime > accumulated_runtime)
		child_runtime = 0;
	return desc;
}

double interrupt::usage_summary(void)
{
	double t;
	t = (accumulated_runtime - child_runtime) / 1000000.0 / measurement_time / 10;
	return t;
}

const char * interrupt::usage_units_summary(void)
{
	return "%";
}


class interrupt * find_create_interrupt(const char *_handler, int nr, int cpu)
{
	char handler[64];
	unsigned int i;
	class interrupt *new_irq;

	pt_strcpy(handler, _handler);
	if (strcmp(handler, "timer")==0)
		sprintf(handler, "timer/%i", cpu);


	for (i = 0; i < all_interrupts.size(); i++) {
		if (all_interrupts[i] && all_interrupts[i]->number == nr && strcmp(handler, all_interrupts[i]->handler) == 0)
			return all_interrupts[i];
	}

	new_irq = new class interrupt(handler, nr);
	all_interrupts.push_back(new_irq);
	return new_irq;
}

void all_interrupts_to_all_power(void)
{
	unsigned int i;
	for (i = 0; i < all_interrupts.size() ; i++)
		if (all_interrupts[i]->accumulated_runtime)
			all_power.push_back(all_interrupts[i]);
}

void clear_interrupts(void)
{
	std::vector<class interrupt *>::iterator it = all_interrupts.begin();
	while (it != all_interrupts.end()) {
		delete *it;
		it = all_interrupts.erase(it);
	}
}