Date: Tue, 11 Apr 2017 00:16:59 -0700 From: Christopher Bowman <crb@chrisbowman.com> To: hackers@freebsd.org Subject: Dtrace oddity Message-ID: <CD5E9B03-6147-4E4D-BED6-6C45022051E3@chrisbowman.com>
next in thread | raw e-mail | index | archive | help
Apologies if I=E2=80=99m sending to the wrong list. I have a small test = program shown at the bottom. It tries to mmap a device for which I=E2=80=99= ve written (a possibly incorrect) driver. When I run the program I get = the following output: =20 crb@retread:63> ./test /dev/sp6050=20 argc =3D 2 argv[0] =3D ./test argv[1] =3D /dev/sp6050 opening device /dev/sp6050 open returned non-zero value mmap failed: EINVAL The man page lists a bunch of reasons for EINVAL so I want to = investigate this and I don=E2=80=99t quite know good strategies to debug = the kernel (yet) so I thought I=E2=80=99d experiment with Dtrace a bit. = Here is the oddity: when I run Dtrace and then run my test program I get = the following output from Dtrace: crb@retread:60> dtrace -n 'syscall:freebsd:mmap:entry /execname =3D=3D = "test"/ {}' dtrace: description 'syscall:freebsd:mmap:entry ' matched 1 probe CPU ID FUNCTION:NAME 0 63401 mmap:entry=20 0 63401 mmap:entry=20 0 63401 mmap:entry=20 0 63401 mmap:entry=20 0 63401 mmap:entry=20 0 63401 mmap:entry=20 0 63401 mmap:entry=20 0 63401 mmap:entry=20 0 63401 mmap:entry=20 0 63401 mmap:entry=20 0 63401 mmap:entry=20 0 63401 mmap:entry=20 I think Dtrace is indicating that the mmap syscall was called 12 times = by my test program yet I can see how the program below would have done = that. Here is my program: /* Copyright (c) 2011 by Christopher R. Bowman. All rights = reserved. */ #include <errno.h> #include <stdio.h> #include <fcntl.h> #include <sys/mman.h> int main (int argc, char ** argv) { int i; printf("argc =3D %d\n", argc); for (i=3D0; i < argc; i++) printf ("argv[%i] =3D %s\n", i, argv[i]); if (argc < 2) { printf("usage: test device\n"); return 0; } printf("opening device %s\n", argv[1]); int device =3D open (argv[1], O_RDWR); if (device =3D=3D 0) { printf ("open of device %s failed\n", argv[1]); return 0; } printf("open returned non-zero value\n"); void *pa =3D mmap (0, 4095, PROT_READ | PROT_WRITE, 0, device, = 0); if (pa =3D=3D MAP_FAILED) { printf ("mmap failed: "); switch (errno) { case EACCES: printf("EACCESS\n"); break; case EBADF: printf("EBADF\n"); break; case EINVAL: printf("EINVAL\n"); break; case ENODEV: printf("ENODEV\n"); break; case ENOMEM: printf("ENOMEM\n"); break; } return 0; } printf("mmap returned non-zero value: %lx\n", (unsigned = long)pa); unsigned int *p =3D (unsigned int *) pa; unsigned char *c =3D (unsigned char *) pa; #define NUM_ITERATIONS 16 for (i=3D0; i < NUM_ITERATIONS; i++){ //BARs are 2Kbytes //*p++ =3D (0xa5a5 + i); *p++ =3D (0x5aa5a5a5); } p =3D (unsigned int *) pa; for (i=3D0; i < NUM_ITERATIONS; i++){ printf("i =3D %d, read_val =3D %x\n", i, *p++); } } Thanks in advance for comments on Dtrace or perhaps program corrections = or ideas why the mmap failed or places to read on kernel debugging or = pointers to a better list to which to send this. Thanks Christopher
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CD5E9B03-6147-4E4D-BED6-6C45022051E3>