summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhunt <hunt>2005-08-03 18:52:23 +0000
committerhunt <hunt>2005-08-03 18:52:23 +0000
commit416730778dd315b64b1f443e5396685c9d0078cd (patch)
tree5ed5eac193c310978b2cb6697ad6b4c6a2ea5870
parent27cffb521607b81eec660ab9f5b8b607d014c692 (diff)
downloadsystemtap-steved-416730778dd315b64b1f443e5396685c9d0078cd.tar.gz
systemtap-steved-416730778dd315b64b1f443e5396685c9d0078cd.tar.xz
systemtap-steved-416730778dd315b64b1f443e5396685c9d0078cd.zip
2005-08-03 Martin Hunt <hunt@redhat.com>
* librelay.c (open_control_channel): Set the receive buffer to 512K, or the max allowed. * stpd.c: Remove "-n" subbug option and change "-b" option so you can specify buffering in different ways. Add a verbose option. Exec the "stp_check" script.
-rw-r--r--runtime/stpd/ChangeLog9
-rw-r--r--runtime/stpd/librelay.c43
-rw-r--r--runtime/stpd/stpd.c81
3 files changed, 112 insertions, 21 deletions
diff --git a/runtime/stpd/ChangeLog b/runtime/stpd/ChangeLog
index 6452fa80..de453759 100644
--- a/runtime/stpd/ChangeLog
+++ b/runtime/stpd/ChangeLog
@@ -1,3 +1,12 @@
+2005-08-03 Martin Hunt <hunt@redhat.com>
+
+ * librelay.c (open_control_channel): Set the receive buffer
+ to 512K, or the max allowed.
+
+ * stpd.c: Remove "-n" subbug option and change "-b" option
+ so you can specify buffering in different ways. Add a verbose option.
+ Exec the "stp_check" script.
+
2005-08-01 Frank Ch. Eigler <fche@redhat.com>
* librelay.c: Correct fwrite api usage.
diff --git a/runtime/stpd/librelay.c b/runtime/stpd/librelay.c
index 4fe9d548..bca63e6e 100644
--- a/runtime/stpd/librelay.c
+++ b/runtime/stpd/librelay.c
@@ -74,9 +74,7 @@ static pthread_t reader[NR_CPUS];
static int control_channel;
/* flags */
-extern int print_only;
-extern int quiet;
-extern int merge;
+extern int print_only, quiet, merge, verbose;
extern unsigned int opt_subbuf_size;
extern unsigned int opt_n_subbufs;
extern char *modname;
@@ -153,13 +151,29 @@ int send_request(int type, void *data, int len)
return err;
}
+#if 0
+static unsigned int get_rmem(void)
+{
+ char buf[32];
+ FILE *fp = fopen ("/proc/sys/net/core/rmem_max", "r");
+ if (fp == NULL)
+ return 0;
+ if (fgets (buf, 32, fp) == NULL) {
+ fclose(fp);
+ return 0;
+ }
+ fclose(fp);
+ return atoi(buf);
+}
+#endif
+
/**
* open_control_channel - create netlink channel
*/
static int open_control_channel()
{
struct sockaddr_nl snl;
- int channel;
+ int channel, rcvsize = 512*1024;
channel = socket(AF_NETLINK, SOCK_RAW, NETLINK_USERSOCK);
if (channel < 0) {
@@ -167,6 +181,9 @@ static int open_control_channel()
return channel;
}
+ if (setsockopt(channel, SOL_SOCKET, SO_RCVBUF, &rcvsize, sizeof(int)))
+ fprintf(stderr, "WARNING: failed to set socket receive buffer to %d\n", rcvsize);
+
memset(&snl, 0, sizeof snl);
snl.nl_family = AF_NETLINK;
snl.nl_pid = getpid();
@@ -451,12 +468,26 @@ int init_stp(const char *relay_filebase, int print_summary)
{
char buf[1024];
struct transport_info ti;
+ pid_t pid;
+ int status;
ncpus = sysconf(_SC_NPROCESSORS_ONLN);
print_totals = print_summary;
- sprintf(buf, "insmod %s _stp_pid=%d", modname, (int)getpid());
- if (system(buf)) {
+ sprintf(buf, "_stp_pid=%d", (int)getpid());
+ if ((pid = vfork()) < 0) {
+ perror ("vfork");
+ exit(-1);
+ } else if (pid == 0) {
+ if (execl("/sbin/insmod", "insmod", modname, buf, NULL) < 0)
+ exit(-1);
+ }
+ if (waitpid(pid, &status, 0) < 0) {
+ perror("waitpid");
+ exit(-1);
+ }
+ if (WIFEXITED(status) && WEXITSTATUS(status)) {
+ perror ("insmod");
fprintf(stderr, "ERROR, couldn't insmod probe module %s\n", modname);
return -1;
}
diff --git a/runtime/stpd/stpd.c b/runtime/stpd/stpd.c
index 006de753..49b3951a 100644
--- a/runtime/stpd/stpd.c
+++ b/runtime/stpd/stpd.c
@@ -23,6 +23,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <strings.h>
+#include <sys/wait.h>
#include "librelay.h"
extern char *optarg;
@@ -32,29 +34,41 @@ extern int optind;
int print_only = 0;
int quiet = 0;
int merge = 1;
+int verbose = 0;
unsigned int opt_subbuf_size = 0;
unsigned int opt_n_subbufs = 0;
+unsigned int buffer_size = 0;
char *modname = NULL;
/* relayfs base file name */
static char stpd_filebase[1024];
+/* stp_check script */
+#ifdef PKGLIBDIR
+char *stp_check=PKGLIBDIR "/stp_check";
+#else
+char *stp_check="stp_check";
+#endif
+
static void usage(char *prog)
{
fprintf(stderr, "\n%s [-m] [-p] [-q] [-b bufsize] [-n num_subbufs] kmod-name\n", prog);
fprintf(stderr, "-m Don't merge per-cpu files.\n");
fprintf(stderr, "-p Print only. Don't log to files.\n");
fprintf(stderr, "-q Quiet. Don't display trace to stdout.\n");
- fprintf(stderr, "-b subbuf_size (override the value in the module)\n");
- fprintf(stderr, "-n subbufs (override the value in the module)\n");
+ fprintf(stderr, "-b buffer size. The systemtap module will specify a buffer size.\n");
+ fprintf(stderr, " Setting one here will override that value. The value should be\n");
+ fprintf(stderr, " an integer between 1 and 64 which be assumed to be the\n");
+ fprintf(stderr, " buffer size in MB. That value will be per-cpu if relayfs is used.\n");
exit(1);
}
int main(int argc, char **argv)
{
- int c;
+ int c, status;
+ pid_t pid;
- while ((c = getopt(argc, argv, "mpqb:n:")) != EOF)
+ while ((c = getopt(argc, argv, "mpqb:n:v")) != EOF)
{
switch (c) {
case 'm':
@@ -66,25 +80,44 @@ int main(int argc, char **argv)
case 'q':
quiet = 1;
break;
- case 'b':
- opt_subbuf_size = (unsigned)atoi(optarg);
- if (!opt_subbuf_size)
- usage(argv[0]);
+ case 'v':
+ verbose = 1;
break;
- case 'n':
- opt_n_subbufs = (unsigned)atoi(optarg);
- if (!opt_n_subbufs)
+ case 'b':
+ {
+ char *ptr;
+ int size = (unsigned)atoi(optarg);
+ if (!size)
usage(argv[0]);
+ ptr = index (optarg, 'x');
+ if (ptr) {
+ ptr++;
+ opt_subbuf_size = (unsigned)atoi(ptr);
+ printf("subbuf_size = %d\n", opt_subbuf_size);
+ opt_n_subbufs = size;
+ } else {
+ if (size > 64) {
+ fprintf(stderr, "Maximum buffer size is 64 (MB)\n");
+ exit(1);
+ }
+ buffer_size = size * 1024 * 1024;
+ opt_subbuf_size = ((size >> 2) + 1) * 65536;
+ opt_n_subbufs = buffer_size / opt_subbuf_size;
+ }
break;
+ }
default:
usage(argv[0]);
}
}
- if ((opt_n_subbufs && !opt_subbuf_size) || (opt_subbuf_size && !opt_n_subbufs)) {
- fprintf (stderr, "You must specify both the number of subbufs and their size.\n");
- usage(argv[0]);
+ if (verbose) {
+ if (buffer_size)
+ printf ("Using a buffer of %u bytes.\n", buffer_size);
+ else if (opt_n_subbufs)
+ printf ("Using %u subbufs of %u bytes.\n", opt_n_subbufs, opt_subbuf_size);
}
+
if (optind < argc)
modname = argv[optind++];
@@ -98,6 +131,24 @@ int main(int argc, char **argv)
usage(argv[0]);
}
+ /* now run the _stp_check script */
+ if ((pid = vfork()) < 0) {
+ perror ("vfork");
+ exit(-1);
+ } else if (pid == 0) {
+ if (execlp(stp_check, stp_check, NULL) < 0)
+ exit (-1);
+ }
+ if (waitpid(pid, &status, 0) < 0) {
+ perror("waitpid");
+ exit(-1);
+ }
+ if (WIFEXITED(status) && WEXITSTATUS(status)) {
+ perror (stp_check);
+ fprintf(stderr, "Could not execute %s\n", stp_check);
+ exit(1);
+ }
+
sprintf(stpd_filebase, "/mnt/relay/%d/cpu", getpid());
if (init_stp(stpd_filebase, !quiet)) {
fprintf(stderr, "Couldn't initialize stpd. Exiting.\n");
@@ -105,7 +156,7 @@ int main(int argc, char **argv)
}
if (stp_main_loop()) {
- printf("Couldn't enter main loop. Exiting.\n");
+ fprintf(stderr,"Couldn't enter main loop. Exiting.\n");
exit(1);
}