GCOV Execution Analysis for hotswap.c

The left column is the number of times the code was executed during the unit test suites.

Exec CodeLine #
 
Source:hotswap.c
1
 
Graph:.libs/hotswap.gcno
2
 
Data:.libs/hotswap.gcda
3
 
Runs:378
4
 
Programs:378
5
 
/*      -*- linux-c -*-
6
 
 *
7
 
 * Copyright (c) 2003 by Intel Corp.
8
 
 * (C) Copyright IBM Corp. 2003, 2004
9
 
 * Copyright (c) 2004 by FORCE Computers.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  This
14
 
 * file and program are licensed under a BSD style license.  See
15
 
 * the Copying file included with the OpenHPI distribution for
16
 
 * full licensing terms.
17
 
 *
18
 
 * Authors:
19
 
 *     Louis Zhuang < address removed >
20
 
 *     Thomas Kanngieser < address removed >
21
 
 *     Racing Guo < address removed >
22
 
 * Contributors:
23
 
 *     David Judkovics < address removed > 
24
 
 */
25
 
26
 
#include <stdio.h>
27
 
#include <stdlib.h>
28
 
#include <string.h>
29
 
30
 
#include <SaHpi.h>
31
 
#include <openhpi.h>
32
 
#include <oh_hotswap.h>
33
 
#include <oh_utils.h>
34
 
35
 
GSList *hs_eq = NULL;
36
 
37
 
void process_hotswap_policy()
38
380 
{
39
380 
        SaHpiTimeT cur, est;	   
40
380 
        struct oh_event e;
41
380 
	struct oh_handler *handler;
42
380 
	struct oh_domain *domain;
43
380 
        RPTable *rpt;
44
380 
	GSList *tmp_hs_eq = NULL;
45
 
46
 
        int (*get_hotswap_state)(void *hnd, SaHpiResourceIdT rid,
47
390 
                                 SaHpiHsStateT *state);
48
 
        
49
390 
        while( hotswap_pop_event(&hs_eq, &e) > 0 ) {
50
10 
                struct oh_resource_data *rd;
51
 
               
52
10 
		domain = oh_get_domain(e.did);
53
10 
		if (!domain) {
54
0 
			dbg("No domain\n");
55
0 
			continue;
56
 
		}
57
 
58
10 
		if (e.type != OH_ET_HPI) {
59
0 
			dbg("Non-hpi event!");
60
0 
			oh_release_domain(domain);
61
0 
			continue;
62
 
		}
63
 
64
10 
		handler = oh_lookup_handler(e.hid);
65
10 
		if (!handler) {
66
0 
			dbg("handler is NULL\n");
67
0 
			oh_release_domain(domain);
68
0 
			continue;
69
 
		}
70
 
71
 
72
 
		/*rpt is impossible NULL */
73
10 
		rpt = &domain->rpt;
74
 
75
10 
        	get_hotswap_state = handler->abi->get_hotswap_state;
76
 
        
77
10 
        	if (!get_hotswap_state) {
78
0 
                	dbg(" Very bad thing here or hotswap not yet supported");
79
0 
			oh_release_domain(domain);
80
0 
                	continue;
81
 
        	}
82
 
83
10 
                if (e.u.hpi_event.event.EventType != SAHPI_ET_HOTSWAP) {
84
0 
                        dbg("Non-hotswap event!");
85
0 
			oh_release_domain(domain);
86
0 
                        continue;
87
 
                }
88
 
                
89
10 
                if (!(e.u.hpi_event.res.ResourceCapabilities & SAHPI_CAPABILITY_MANAGED_HOTSWAP)) {
90
0 
                        dbg("Non-hotswapable resource?!");
91
0 
			oh_release_domain(domain);
92
0 
                        continue;
93
 
                }
94
 
                
95
10 
                rd = oh_get_resource_data(rpt, e.u.hpi_event.res.ResourceId);
96
10 
                if (!rd) {
97
0 
                        dbg( "Can't find resource data for Resource %d", e.u.hpi_event.res.ResourceId);
98
0 
                        oh_release_domain(domain);
99
0 
			continue;
100
 
                }
101
 
102
10 
                if (rd->controlled) {
103
0 
                        dbg();
104
0 
                        oh_release_domain(domain);
105
0 
			continue;
106
 
                }
107
 
108
10 
                oh_gettimeofday(&cur);
109
 
110
10 
                if (e.u.hpi_event.event.EventDataUnion.HotSwapEvent.HotSwapState 
111
 
                    == SAHPI_HS_STATE_INSERTION_PENDING) {
112
5 
                        est = e.u.hpi_event.event.Timestamp + get_hotswap_auto_insert_timeout();
113
 
                        
114
5 
                        if (cur>=est) {
115
5 
                                handler->abi->set_hotswap_state( handler->hnd, e.u.hpi_event.res.ResourceId,
116
 
                                                                 SAHPI_HS_STATE_ACTIVE);
117
 
                        }else {
118
 
				/*push again in order to process in the feature*/
119
0 
				hotswap_push_event(&tmp_hs_eq, &e);
120
 
			}
121
5 
                } else if (e.u.hpi_event.event.EventDataUnion.HotSwapEvent.HotSwapState
122
 
                           == SAHPI_HS_STATE_EXTRACTION_PENDING) {
123
5 
                        est = e.u.hpi_event.event.Timestamp + rd->auto_extract_timeout;
124
5 
                        if (cur>=est) {
125
5 
                                handler->abi->set_hotswap_state(handler->hnd, e.u.hpi_event.res.ResourceId,
126
 
                                                                SAHPI_HS_STATE_INACTIVE);
127
 
                        } else {
128
 
				/*push again in order to process in the feature*/
129
0 
                                hotswap_push_event(&tmp_hs_eq, &e);
130
 
			}
131
 
                } else {
132
0 
                        dbg();
133
 
                }
134
10 
		oh_release_domain(domain);
135
 
        }
136
 
137
 
	/* Make sure:
138
 
	   1. hs_eq has no event (hotswap_pop_event(&e) > 0)
139
 
	   2. process_hotswap_policy is not reentry. (only one thread call this function)
140
 
	*/
141
 
142
380 
	hs_eq = tmp_hs_eq;
143
 
}
144
 
145
 
/*
146
 
 * session_push_event pushs and event into a session.
147
 
 * We store a copy of event so that caller of the function
148
 
 * needn't care about ref counter of the event.
149
 
*/
150
 
151
 
int hotswap_push_event(GSList **hs_eq, struct oh_event *e)
152
10 
{
153
10 
        struct oh_event *e1;
154
 
155
10 
        data_access_lock();
156
 
157
10 
        e1 = malloc(sizeof(*e1));
158
10 
        if (!e1) {
159
0 
                dbg("Out of memory!");
160
0 
                data_access_unlock();
161
0 
                return -1;
162
 
        }
163
10 
        memcpy(e1, e, sizeof(*e));
164
 
165
10 
        *hs_eq = g_slist_append(*hs_eq, (gpointer *) e1);
166
 
        
167
10 
        data_access_unlock();
168
 
169
10 
        return 0;
170
 
}
171
 
172
 
/*
173
 
 * session_pop_event - pops events off the session.  
174
 
 *
175
 
 * return codes are left as was, but it seems that return 1 for success
176
 
 * here doesn't jive with the rest of the exit codes
177
 
 */
178
 
179
 
int hotswap_pop_event(GSList **hs_eq, struct oh_event *e) 
180
390 
{
181
390 
        GSList *head;
182
 
        
183
390 
        data_access_lock();
184
 
185
390 
        if (g_slist_length(*hs_eq) == 0) {
186
380 
                data_access_unlock();
187
380 
                return 0;
188
 
        }
189
 
       
190
10 
        head = *hs_eq;
191
10 
        *hs_eq = g_slist_remove_link(*hs_eq, head);
192
 
        
193
10 
        memcpy(e, head->data, sizeof(*e));
194
 
        
195
10 
        free(head->data);
196
10 
        g_slist_free_1(head);
197
 
        
198
10 
        data_access_unlock();
199
 
200
10 
        return 1;
201
 
}
202
 
203
 
/*
204
 
 * session_has_event - query if the session has events
205
 
 */
206
 
int hotswap_has_event(GSList *hs_eq)
207
0 
{
208
0 
        return (hs_eq == NULL) ? 0 : 1;
209
 
}
210
 
211
 
static SaHpiTimeoutT hotswap_auto_insert_timeout = 0;
212
 
213
 
SaHpiTimeoutT get_hotswap_auto_insert_timeout(void)
214
11 
{
215
11 
        return hotswap_auto_insert_timeout;
216
 
}
217
 
218
 
void set_hotswap_auto_insert_timeout(SaHpiTimeoutT to)
219
6 
{
220
6 
        hotswap_auto_insert_timeout = to;
221
 
}
222
 
223
 
224
 
/* default auto extract timeout */
225
 
static SaHpiTimeoutT hotswap_auto_extract_timeout = 0;
226
 
227
 
SaHpiTimeoutT get_default_hotswap_auto_extract_timeout(void)
228
1098 
{
229
1098 
        return hotswap_auto_extract_timeout;
230
 
}
231
 
232
 
void set_default_hotswap_auto_extract_timeout(SaHpiTimeoutT to)
233
0 
{
234
0 
        hotswap_auto_extract_timeout = to;
235
 
}
236