View | Details | Raw Unified | Return to bug 3858 | Differences between
and this patch

Collapse All | Expand All

(-)src.MAIN/runtime/print.c (-6 / +72 lines)
Lines 39-45 typedef struct __stp_pbuf { Link Here
39
	char buf[STP_BUFFER_SIZE];
39
	char buf[STP_BUFFER_SIZE];
40
} _stp_pbuf;
40
} _stp_pbuf;
41
41
42
#define __DEF_EXPORT_FN(fn, postfix) fn ## _ ## postfix
43
#define DEF_EXPORT_FN(fn, postfix) __DEF_EXPORT_FN(fn, postfix)
44
45
#if defined(RELAY_GUEST)
46
#ifdef RELAY_HOST
47
	#error "Cannot specify both RELAY_HOST and RELAY_GUEST"
48
#endif
49
#define EXPORT_FN(fn) DEF_EXPORT_FN(fn, RELAY_GUEST)
50
#elif defined(RELAY_HOST)
51
#define EXPORT_FN(fn) DEF_EXPORT_FN(fn, RELAY_HOST)
52
#else /* defined(RELAY_GUEST) || defined(RELAY_HOST) */
53
#define EXPORT_FN(fn) fn
54
#endif
55
56
#if defined(RELAY_GUEST) || defined(RELAY_HOST)
57
/* convert exported name to internal name */
58
#define _stp_get_pbuf() EXPORT_FN(_stp_get_pbuf)()
59
#define _stp_print_flush() EXPORT_FN(_stp_print_flush)()
60
#define _stp_reserve_bytes(n) EXPORT_FN(_stp_reserve_bytes)(n)
61
#define _stp_print_binary(n...) EXPORT_FN(_stp_print_binary)(n)
62
#define _stp_printf(fmt...) EXPORT_FN(_stp_printf)(fmt)
63
#define _stp_print(s) EXPORT_FN(_stp_print)(s)
64
#define _stp_print_char(c) EXPORT_FN(_stp_print_char)(c)
65
#endif
66
67
#ifndef RELAY_GUEST
42
void *Stp_pbuf = NULL;
68
void *Stp_pbuf = NULL;
69
#endif
43
70
44
/** private buffer for _stp_log() */
71
/** private buffer for _stp_log() */
45
#define STP_LOG_BUF_LEN 256
72
#define STP_LOG_BUF_LEN 256
Lines 47-52 void *Stp_pbuf = NULL; Link Here
47
typedef char _stp_lbuf[STP_LOG_BUF_LEN];
74
typedef char _stp_lbuf[STP_LOG_BUF_LEN];
48
void *Stp_lbuf = NULL;
75
void *Stp_lbuf = NULL;
49
76
77
#ifdef RELAY_GUEST
78
79
int _stp_print_init (void)
80
{
81
	/* now initialize IO buffer used in io.c */
82
	Stp_lbuf = alloc_percpu(_stp_lbuf);
83
	if (unlikely(Stp_lbuf == 0)) {
84
		return -1;
85
	}
86
	_stp_allocated_memory += (sizeof(_stp_lbuf)) * num_online_cpus();
87
	return 0;
88
}
89
void _stp_print_cleanup (void)
90
{
91
	if (Stp_lbuf)
92
		free_percpu(Stp_lbuf);
93
}
94
extern _stp_pbuf * EXPORT_FN(_stp_get_pbuf) (void);
95
extern void EXPORT_FN(_stp_print_flush) (void);
96
extern void * EXPORT_FN(_stp_reserve_bytes) (int numbytes);
97
extern void EXPORT_FN(_stp_print_binary) (int num, ...);
98
extern void EXPORT_FN(_stp_printf) (const char *fmt, ...);
99
extern void EXPORT_FN(_stp_print) (const char *str);
100
extern void EXPORT_FN(_stp_print_char) (const char c);
101
102
#else
50
/* create percpu print and io buffers */
103
/* create percpu print and io buffers */
51
int _stp_print_init (void)
104
int _stp_print_init (void)
52
{
105
{
Lines 88-94 void _stp_print_cleanup (void) Link Here
88
141
89
/** Reserves space in the output buffer for direct I/O.
142
/** Reserves space in the output buffer for direct I/O.
90
 */
143
 */
91
static void * _stp_reserve_bytes (int numbytes)
144
void * EXPORT_FN(_stp_reserve_bytes) (int numbytes)
92
{
145
{
93
	_stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id());
146
	_stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id());
94
	int size = STP_BUFFER_SIZE - pb->len;
147
	int size = STP_BUFFER_SIZE - pb->len;
Lines 112-118 static void * _stp_reserve_bytes (int nu Link Here
112
 * than doing the same in _stp_vsnprintf().
165
 * than doing the same in _stp_vsnprintf().
113
 * @sa _stp_vsnprintf()
166
 * @sa _stp_vsnprintf()
114
 */
167
 */
115
static void _stp_print_binary (int num, ...)
168
void EXPORT_FN(_stp_print_binary) (int num, ...)
116
{
169
{
117
	va_list vargs;
170
	va_list vargs;
118
	int i;
171
	int i;
Lines 137-143 static void _stp_print_binary (int num, Link Here
137
 *
190
 *
138
 * @sa _stp_print_flush()
191
 * @sa _stp_print_flush()
139
 */
192
 */
140
void _stp_printf (const char *fmt, ...)
193
void EXPORT_FN(_stp_printf) (const char *fmt, ...)
141
{
194
{
142
	int num;
195
	int num;
143
	va_list args;
196
	va_list args;
Lines 173-179 void _stp_printf (const char *fmt, ...) Link Here
173
 * @param str A C string (char *)
226
 * @param str A C string (char *)
174
 */
227
 */
175
228
176
void _stp_print (const char *str)
229
void EXPORT_FN(_stp_print) (const char *str)
177
{
230
{
178
	int num = strlen (str);
231
	int num = strlen (str);
179
	_stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id());
232
	_stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id());
Lines 187-193 void _stp_print (const char *str) Link Here
187
	pb->len += num;
240
	pb->len += num;
188
}
241
}
189
242
190
void _stp_print_char (const char c)
243
void EXPORT_FN(_stp_print_char) (const char c)
191
{
244
{
192
	char *buf;
245
	char *buf;
193
	_stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id());
246
	_stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id());
Lines 198-204 void _stp_print_char (const char c) Link Here
198
	pb->buf[pb->len] = c;
251
	pb->buf[pb->len] = c;
199
	pb->len ++;
252
	pb->len ++;
200
}
253
}
201
254
_stp_pbuf * EXPORT_FN(_stp_get_pbuf) (void)
255
{
256
	return per_cpu_ptr(Stp_pbuf, smp_processor_id());
257
}
258
#ifdef RELAY_HOST
259
EXPORT_SYMBOL_GPL(EXPORT_FN(_stp_get_pbuf));
260
EXPORT_SYMBOL_GPL(EXPORT_FN(_stp_print_flush));
261
EXPORT_SYMBOL_GPL(EXPORT_FN(_stp_reserve_bytes));
262
EXPORT_SYMBOL_GPL(EXPORT_FN(_stp_print_binary));
263
EXPORT_SYMBOL_GPL(EXPORT_FN(_stp_printf));
264
EXPORT_SYMBOL_GPL(EXPORT_FN(_stp_print));
265
EXPORT_SYMBOL_GPL(EXPORT_FN(_stp_print_char));
266
#endif /* RELAY_HOST */
267
#endif /* RELAY_GUEST */
202
268
203
/* This function is used when printing maps or stats. */
269
/* This function is used when printing maps or stats. */
204
/* Probably belongs elsewhere, but is here for now. */
270
/* Probably belongs elsewhere, but is here for now. */
(-)src.MAIN/runtime/stack.c (-1 / +1 lines)
Lines 76-82 void _stp_stack_snprint (char *str, int Link Here
76
	/* To get a string, we use a simple trick. First flush the print buffer, */
76
	/* To get a string, we use a simple trick. First flush the print buffer, */
77
	/* then call _stp_stack_print, then copy the result into the output string  */
77
	/* then call _stp_stack_print, then copy the result into the output string  */
78
	/* and clear the print buffer. */
78
	/* and clear the print buffer. */
79
	_stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id());
79
	_stp_pbuf *pb = _stp_get_pbuf();
80
	_stp_print_flush();
80
	_stp_print_flush();
81
	_stp_stack_print(regs, verbose, pi);
81
	_stp_stack_print(regs, verbose, pi);
82
	strlcpy(str, pb->buf, size < (int)pb->len ? size : (int)pb->len);
82
	strlcpy(str, pb->buf, size < (int)pb->len ? size : (int)pb->len);
(-)src.MAIN/runtime/print_new.c (-1 / +1 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
spinlock_t _stp_print_lock = SPIN_LOCK_UNLOCKED;
18
spinlock_t _stp_print_lock = SPIN_LOCK_UNLOCKED;
19
19
20
void _stp_print_flush (void)
20
void EXPORT_FN(_stp_print_flush) (void)
21
{
21
{
22
	_stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id());
22
	_stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id());
23
	uint32_t len = pb->len;
23
	uint32_t len = pb->len;
(-)src.MAIN/runtime/print_old.c (-1 / +1 lines)
Lines 16-22 Link Here
16
 * @note Preemption must be disabled to use this.
16
 * @note Preemption must be disabled to use this.
17
 */
17
 */
18
18
19
void _stp_print_flush (void)
19
void EXPORT_FN(_stp_print_flush) (void)
20
{
20
{
21
	_stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id());
21
	_stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id());
22
	uint32_t len = pb->len;
22
	uint32_t len = pb->len;

Return to bug 3858