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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/* -*- linux-c -*-
* Print Flush Function
* Copyright (C) 2007-2008 Red Hat Inc.
*
* This file is part of systemtap, and is free software. You can
* redistribute it and/or modify it under the terms of the GNU General
* Public License (GPL); either version 2, or (at your option) any
* later version.
*/
/** Send the print buffer to the transport now.
* Output accumulates in the print buffer until it
* is filled, or this is called. This MUST be called before returning
* from a probe or accumulated output in the print buffer will be lost.
*
* @note Preemption must be disabled to use this.
*/
static DEFINE_SPINLOCK(_stp_print_lock);
void EXPORT_FN(stp_print_flush) (_stp_pbuf *pb)
{
uint32_t len = pb->len;
/* check to see if there is anything in the buffer */
dbug_trans(1, "len = %ud\n", len);
if (likely (len == 0))
return;
pb->len = 0;
//DRS FIXME: this digs down too deep in internals
// if (unlikely(!_stp_utt || _stp_utt->trace_state != Utt_trace_running))
// return;
#define MAX_RESERVE_SIZE (4080 /*BUF_PAGE_SIZE*/ - sizeof(struct _stp_entry) - 10)
#ifdef STP_BULKMODE
{
struct _stp_entry *entry;
#ifdef NO_PERCPU_HEADERS
{
uint32_t cnt;
char *bufp = pb->buf;
printk(KERN_ERR "%s:%d - flushing %d(%d) bytes\n",
__FUNCTION__, __LINE__, pb->len, len);
while (len > 0) {
if (len > MAX_RESERVE_SIZE) {
len -= MAX_RESERVE_SIZE;
cnt = MAX_RESERVE_SIZE;
}
else {
cnt = len;
len = 0;
}
printk(KERN_ERR "%s:%d - reserving %d bytes\n",
__FUNCTION__, __LINE__, cnt);
entry = _stp_data_write_reserve(cnt);
if (likely(entry)) {
memcpy(entry->buf, bufp, cnt);
_stp_data_write_commit(entry);
bufp += cnt;
}
else {
atomic_inc (&_stp_transport_failures);
break;
}
}
}
#else
#undef MAX_RESERVE_SIZE
#define MAX_RESERVE_SIZE (4080 /*BUF_PAGE_SIZE*/ - sizeof(struct _stp_entry) - 10 - sizeof(struct _stp_trace))
{
uint32_t cnt;
char *bufp = pb->buf;
struct _stp_trace t = { .sequence = _stp_seq_inc(),
.pdu_len = len};
printk(KERN_ERR "%s:%d - flushing %d(%d) bytes\n",
__FUNCTION__, __LINE__, pb->len, len);
entry = _stp_data_write_reserve(sizeof(struct _stp_trace));
if (likely(entry)) {
/* prevent unaligned access by using
* memcpy() */
memcpy(entry->buf, &t, sizeof(t));
_stp_data_write_commit(entry);
}
else {
atomic_inc (&_stp_transport_failures);
return;
}
while (len > 0) {
if (len > MAX_RESERVE_SIZE) {
len -= MAX_RESERVE_SIZE;
cnt = MAX_RESERVE_SIZE;
}
else {
cnt = len;
len = 0;
}
printk(KERN_ERR "%s:%d - reserving %d bytes\n",
__FUNCTION__, __LINE__, cnt);
entry = _stp_data_write_reserve(cnt);
if (likely(entry)) {
memcpy(entry->buf, bufp, cnt);
_stp_data_write_commit(entry);
bufp += cnt;
}
else {
atomic_inc (&_stp_transport_failures);
break;
}
}
}
#if 0
void *buf = utt_reserve(_stp_utt,
sizeof(struct _stp_trace) + len);
if (likely(buf)) {
struct _stp_trace t = { .sequence = _stp_seq_inc(),
.pdu_len = len};
memcpy(buf, &t, sizeof(t)); // prevent unaligned access
memcpy(buf + sizeof(t), pb->buf, len);
} else
atomic_inc (&_stp_transport_failures);
#endif
#endif
}
#else
{
struct _stp_entry *entry;
unsigned long flags;
dbug_trans(1, "calling _stp_data_write...\n");
spin_lock_irqsave(&_stp_print_lock, flags);
#if 0
entry = _stp_data_write_reserve(len);
if (likely(entry)) {
memcpy(entry->buf, pb->buf, len);
_stp_data_write_commit(entry);
}
else
#endif
{
uint32_t cnt;
char *bufp = pb->buf;
//#define MAX_RESERVE_SIZE (4080 /*BUF_PAGE_SIZE*/ - sizeof(struct _stp_entry) - 10)
printk(KERN_ERR "%s:%d - flushing %d(%d) bytes\n",
__FUNCTION__, __LINE__, pb->len, len);
while (len > 0) {
if (len > MAX_RESERVE_SIZE) {
len -= MAX_RESERVE_SIZE;
cnt = MAX_RESERVE_SIZE;
}
else {
cnt = len;
len = 0;
}
printk(KERN_ERR "%s:%d - reserving %d bytes\n",
__FUNCTION__, __LINE__, cnt);
entry = _stp_data_write_reserve(cnt);
if (likely(entry)) {
memcpy(entry->buf, bufp, cnt);
_stp_data_write_commit(entry);
bufp += cnt;
}
else {
atomic_inc (&_stp_transport_failures);
break;
}
}
}
spin_unlock_irqrestore(&_stp_print_lock, flags);
}
#endif /* STP_BULKMODE */
}
|