File: bus.c

package info (click to toggle)
mcelog 104-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 996 kB
  • ctags: 1,508
  • sloc: ansic: 7,739; sh: 481; makefile: 87
file content (129 lines) | stat: -rw-r--r-- 3,312 bytes parent folder | download
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
/* Copyright (C) 20014 Intel Corporation
   Author: Rui Wang
   Handle 'Bus and Interconnect' error threshold indications.

   mcelog 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.

   mcelog 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 find a copy of v2 of the GNU General Public License somewhere
   on your Linux system. */
#define _GNU_SOURCE 1
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "memutil.h"
#include "mcelog.h"
#include "config.h"
#include "trigger.h"
#include "bus.h"

static char *bus_trigger, *iomca_trigger;

enum {
	MAX_ENV = 20,
};

void bus_setup(void)
{
	bus_trigger = config_string("socket", "bus-uc-threshold-trigger");
	if (bus_trigger && trigger_check(bus_trigger) < 0) {
		SYSERRprintf("Cannot access bus threshold trigger `%s'",
				bus_trigger);
		exit(1);
	}

	iomca_trigger = config_string("socket", "iomca-threshold-trigger");
	if (iomca_trigger && trigger_check(iomca_trigger) < 0) {
		SYSERRprintf("Cannot access iomca threshold trigger `%s'",
				iomca_trigger);
		exit(1);
	}
}

void run_bus_trigger(int socket, int cpu, char *level, char *pp, char *rrrr,
		char *ii, char *timeout)
{
	int ei = 0;
	char *env[MAX_ENV];
	int i;
	char *msg;
	char *location;

	if (socket >= 0)
		asprintf(&location, "CPU %d on socket %d", cpu, socket);
	else
		asprintf(&location, "CPU %d", cpu);
	asprintf(&msg, "%s received Bus and Interconnect Errors in %s",
		location, ii);
	asprintf(&env[ei++], "LOCATION=%s", location);
	free(location);

	if (!bus_trigger)
		goto out;

	if (socket >= 0)
		asprintf(&env[ei++], "SOCKETID=%d", socket);
	asprintf(&env[ei++], "MESSAGE=%s", msg);
	asprintf(&env[ei++], "CPU=%d", cpu);
	asprintf(&env[ei++], "LEVEL=%s", level);
	asprintf(&env[ei++], "PARTICIPATION=%s", pp);
	asprintf(&env[ei++], "REQUEST=%s", rrrr);
	asprintf(&env[ei++], "ORIGIN=%s", ii);
	asprintf(&env[ei++], "TIMEOUT=%s", timeout);
	env[ei] = NULL;
	assert(ei < MAX_ENV);

	run_trigger(bus_trigger, NULL, env);
	for (i = 0; i < ei; i++)
		free(env[i]);
out:
	free(msg);
}

void run_iomca_trigger(int socket, int cpu, int seg, int bus, int dev, int fn)
{
	int ei = 0;
	char *env[MAX_ENV];
	int i;
	char *msg;
	char *location;

	if (socket >= 0)
		asprintf(&location, "CPU %d on socket %d", cpu, socket);
	else
		asprintf(&location, "CPU %d", cpu);
	asprintf(&msg, "%s received IO MCA Errors from %x:%02x:%02x.%x",
		location, seg, bus, dev, fn);
	asprintf(&env[ei++], "LOCATION=%s", location);
	free(location);

	if (!iomca_trigger)
		goto out;

	if (socket >= 0)
		asprintf(&env[ei++], "SOCKETID=%d", socket);
	asprintf(&env[ei++], "MESSAGE=%s", msg);
	asprintf(&env[ei++], "CPU=%d", cpu);
	asprintf(&env[ei++], "SEG=%x", seg);
	asprintf(&env[ei++], "BUS=%02x", bus);
	asprintf(&env[ei++], "DEVICE=%02x", dev);
	asprintf(&env[ei++], "FUNCTION=%x", fn);
	env[ei] = NULL;
	assert(ei < MAX_ENV);

	run_trigger(iomca_trigger, NULL, env);
	for (i = 0; i < ei; i++)
		free(env[i]);
out:
	free(msg);

}