From owner-freebsd-hackers@freebsd.org Thu Dec 15 16:47:34 2016 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 64AB6C81857 for ; Thu, 15 Dec 2016 16:47:34 +0000 (UTC) (envelope-from lidl@pix.net) Received: from hydra.pix.net (hydra.pix.net [IPv6:2001:470:e254:11::4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mail.pix.net", Issuer "Pix.Com Technologies LLC CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 406B01925 for ; Thu, 15 Dec 2016 16:47:34 +0000 (UTC) (envelope-from lidl@pix.net) Received: from torb.pix.net (torb.pix.net [192.168.16.32]) (authenticated bits=0) by hydra.pix.net (8.16.0.19/8.15.2) with ESMTPA id uBFGlX9U077559; Thu, 15 Dec 2016 11:47:33 -0500 (EST) (envelope-from lidl@pix.net) Subject: Re: How to use sem_timedwait? To: freebsd-hackers@freebsd.org References: <20161214074228.zh6q5zya2gszw4g6@hal9000.meka.no-ip.org> <1481748960.1889.398.camel@freebsd.org> <20161215002906.mllorgvvuovbdtze@hal9000.meka.no-ip.org> <1481775511.1889.450.camel@freebsd.org> <1481776532.1889.461.camel@freebsd.org> From: Kurt Lidl Message-ID: <44ad49f5-75ec-7c1d-28dc-25df08c67148@pix.net> Date: Thu, 15 Dec 2016 11:47:33 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <1481776532.1889.461.camel@freebsd.org> Content-Type: text/plain; charset=iso-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Dec 2016 16:47:34 -0000 On 12/14/16 11:35 PM, Ian Lepore wrote: > /* > * This tests kevent timer events to make sure that they are properly > * metronomic. That is, each event should occur at the requested > * interval following the prior event, and in particular the phase of > * event delivery should not drift because of the time it takes to > * process the event and schedule the next one in the kernel. (i.e., > * this is a userland test of kernel kevent timer performance.) > * Because it's hard to measure the tiny increments of time between > * each sleep, we run a loop that takes several seconds and look for > * the total elapsed time to be increment*loopcount plus a tiny bit of > * overhead for getting the ending time. > */ > > #include > #include > #include > #include > #include > #include > #include > #include > > int > main(int argc, char ** argv) > { > int i, interval; > int64_t nsec; > int kq,num_events; > struct kevent inqueue; > struct kevent outqueue; > struct timespec start,end; > > // argument is timer interval in nanoseconds. > if (argc > 1) > interval = strtoul(argv[1], NULL, 0); > else > interval = 1000000; > > if ((kq = kqueue()) == -1) { > fprintf(stderr, "kqueue errno = %s", strerror(errno)); > exit(EXIT_FAILURE); > } > EV_SET(&inqueue, 1, EVFILT_TIMER, EV_ADD | EV_ENABLE, > NOTE_NSECONDS, interval, 0); > > clock_gettime(CLOCK_MONOTONIC_PRECISE, &start); > > for (i = 0; i < 10000000000 / interval; i++) { > num_events = kevent(kq, &inqueue, 1, &outqueue, 1, NULL); > if (num_events == -1) { > fprintf(stderr, "kevent errno = %s", strerror(errno)); > exit(EXIT_FAILURE); > } else if (outqueue.flags & EV_ERROR) { > fprintf(stderr, "EV_ERROR: %s\n", strerror(outqueue.data)); > exit(EXIT_FAILURE); > } > if (num_events != 1) > printf("num_events %d at i %d\n", num_events, i); > } > clock_gettime(CLOCK_MONOTONIC_PRECISE, &end); > > nsec = (end.tv_sec * 1000000000LL + end.tv_nsec) - > (start.tv_sec * 1000000000LL + start.tv_nsec); > printf("nsec = %jd for %d loops of %d nsec\n", > (intmax_t)nsec, i, interval); > > close(kq); > return EXIT_SUCCESS; > } When I run this code on a sparc64, it panics the machine! lidl@ton-148: ./x panic: trap: fast data access mmu miss (kernel) KDB: stack backtrace: vpanic() at vpanic+0xfc panic() at panic+0x20 trap() at trap+0x554 -- fast data access mmu miss tar=0xc09eda8f %o7=0xc039b344 -- userland() at filt_timerattach+0x78 user trace: trap %o7=0xc039b344 pc 0xc039b378, sp 0xedebe761 done KDB: enter: panic [ thread pid 1263 tid 100583 ] Stopped at kdb_enter+0x80: ta %xcc, 1 db> Oops. -Kurt