1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2003 Cluster File Systems, Inc.
5 * Author: Eric Barton <eeb@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 # define EXPORT_SYMTAB
27 #include <linux/config.h>
28 #include <linux/module.h>
29 #include <linux/kmod.h>
30 #include <linux/kernel.h>
31 #include <linux/kernel.h>
33 #include <linux/string.h>
34 #include <linux/stat.h>
35 #include <linux/errno.h>
36 #include <linux/smp_lock.h>
37 #include <linux/unistd.h>
38 #include <linux/interrupt.h>
39 #include <asm/system.h>
40 #include <asm/uaccess.h>
42 #define DEBUG_SUBSYSTEM S_PORTALS
44 #include <libcfs/kp30.h>
50 lwt_cpu_t lwt_cpus[NR_CPUS];
53 int lwt_pages_per_cpu;
55 /* NB only root is allowed to retrieve LWT info; it's an open door into the
59 lwt_lookup_string (int *size, char *knl_ptr,
60 char *user_ptr, int user_size)
64 /* knl_ptr was retrieved from an LWT snapshot and the caller wants to
65 * turn it into a string. NB we can crash with an access violation
66 * trying to determine the string length, so we're trusting our
69 if (!capable(CAP_SYS_ADMIN))
76 *size = strnlen (knl_ptr, maxsize - 1) + 1;
78 if (user_ptr != NULL) {
82 if (copy_to_user (user_ptr, knl_ptr, *size))
85 /* Did I truncate the string? */
86 if (knl_ptr[*size - 1] != 0)
87 copy_to_user (user_ptr + *size - 4, "...", 4);
94 lwt_control (int enable, int clear)
100 if (!capable(CAP_SYS_ADMIN))
107 /* give people some time to stop adding traces */
108 schedule_timeout(10);
111 for (i = 0; i < num_online_cpus(); i++) {
112 p = lwt_cpus[i].lwtc_current_page;
120 for (j = 0; j < lwt_pages_per_cpu; j++) {
121 memset (p->lwtp_events, 0, PAGE_SIZE);
123 p = list_entry (p->lwtp_list.next,
124 lwt_page_t, lwtp_list);
138 lwt_snapshot (cycles_t *now, int *ncpu, int *total_size,
139 void *user_ptr, int user_size)
141 const int events_per_page = PAGE_SIZE / sizeof(lwt_event_t);
142 const int bytes_per_page = events_per_page * sizeof(lwt_event_t);
147 if (!capable(CAP_SYS_ADMIN))
150 *ncpu = num_online_cpus();
151 *total_size = num_online_cpus() * lwt_pages_per_cpu * bytes_per_page;
154 if (user_ptr == NULL)
157 for (i = 0; i < num_online_cpus(); i++) {
158 p = lwt_cpus[i].lwtc_current_page;
163 for (j = 0; j < lwt_pages_per_cpu; j++) {
164 if (copy_to_user(user_ptr, p->lwtp_events,
168 user_ptr = ((char *)user_ptr) + bytes_per_page;
169 p = list_entry(p->lwtp_list.next,
170 lwt_page_t, lwtp_list);
184 for (i = 0; i < num_online_cpus(); i++)
185 if (lwt_cpus[i].lwtc_current_page != NULL)
188 LASSERT (!lwt_enabled);
190 /* NULL pointers, zero scalars */
191 memset (lwt_cpus, 0, sizeof (lwt_cpus));
192 lwt_pages_per_cpu = LWT_MEMORY / (num_online_cpus() * PAGE_SIZE);
194 for (i = 0; i < num_online_cpus(); i++)
195 for (j = 0; j < lwt_pages_per_cpu; j++) {
196 struct page *page = alloc_page (GFP_KERNEL);
200 CERROR ("Can't allocate page\n");
205 PORTAL_ALLOC(lwtp, sizeof (*lwtp));
207 CERROR ("Can't allocate lwtp\n");
213 lwtp->lwtp_page = page;
214 lwtp->lwtp_events = page_address(page);
215 memset (lwtp->lwtp_events, 0, PAGE_SIZE);
218 INIT_LIST_HEAD (&lwtp->lwtp_list);
219 lwt_cpus[i].lwtc_current_page = lwtp;
221 list_add (&lwtp->lwtp_list,
222 &lwt_cpus[i].lwtc_current_page->lwtp_list);
241 for (i = 0; i < num_online_cpus(); i++)
242 while (lwt_cpus[i].lwtc_current_page != NULL) {
243 lwt_page_t *lwtp = lwt_cpus[i].lwtc_current_page;
245 if (list_empty (&lwtp->lwtp_list)) {
246 lwt_cpus[i].lwtc_current_page = NULL;
248 lwt_cpus[i].lwtc_current_page =
249 list_entry (lwtp->lwtp_list.next,
250 lwt_page_t, lwtp_list);
252 list_del (&lwtp->lwtp_list);
255 __free_page (lwtp->lwtp_page);
256 PORTAL_FREE (lwtp, sizeof (*lwtp));
260 EXPORT_SYMBOL(lwt_enabled);
261 EXPORT_SYMBOL(lwt_cpus);
263 EXPORT_SYMBOL(lwt_init);
264 EXPORT_SYMBOL(lwt_fini);
265 EXPORT_SYMBOL(lwt_lookup_string);
266 EXPORT_SYMBOL(lwt_control);
267 EXPORT_SYMBOL(lwt_snapshot);