From owner-svn-src-user@FreeBSD.ORG Sun Nov 23 00:23:58 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 744801065672; Sun, 23 Nov 2008 00:23:58 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 61CB88FC0A; Sun, 23 Nov 2008 00:23:58 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mAN0Nwc9033505; Sun, 23 Nov 2008 00:23:58 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mAN0NwBC033504; Sun, 23 Nov 2008 00:23:58 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200811230023.mAN0NwBC033504@svn.freebsd.org> From: Kip Macy Date: Sun, 23 Nov 2008 00:23:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185195 - user/kmacy/HEAD_fast_multi_xmit/sys/sys X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Nov 2008 00:23:58 -0000 Author: kmacy Date: Sun Nov 23 00:23:58 2008 New Revision: 185195 URL: http://svn.freebsd.org/changeset/base/185195 Log: - fix buf_ring_peek - don't enable debugging Modified: user/kmacy/HEAD_fast_multi_xmit/sys/sys/buf_ring.h Modified: user/kmacy/HEAD_fast_multi_xmit/sys/sys/buf_ring.h ============================================================================== --- user/kmacy/HEAD_fast_multi_xmit/sys/sys/buf_ring.h Sun Nov 23 00:22:52 2008 (r185194) +++ user/kmacy/HEAD_fast_multi_xmit/sys/sys/buf_ring.h Sun Nov 23 00:23:58 2008 (r185195) @@ -56,8 +56,6 @@ #error "unknown compiler" #endif -#define DEBUG_BUFRING 1 - #if defined(INVARIANTS) && !defined(DEBUG_BUFRING) #define DEBUG_BUFRING 1 #endif @@ -245,7 +243,10 @@ buf_ring_peek(struct buf_ring *br) panic("lock not held on single consumer dequeue"); #endif mb(); - return (br->br_ring[br->br_cons_tail]); + if (br->br_cons_head == br->br_prod_tail) + return (NULL); + + return (br->br_ring[br->br_cons_head]); } static __inline int From owner-svn-src-user@FreeBSD.ORG Sun Nov 23 00:27:16 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A05041065673; Sun, 23 Nov 2008 00:27:16 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8DFD78FC0C; Sun, 23 Nov 2008 00:27:16 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mAN0RGex033598; Sun, 23 Nov 2008 00:27:16 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mAN0RGsO033596; Sun, 23 Nov 2008 00:27:16 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200811230027.mAN0RGsO033596@svn.freebsd.org> From: Kip Macy Date: Sun, 23 Nov 2008 00:27:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185196 - user/kmacy/HEAD_fast_multi_xmit/sys/dev/cxgb X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Nov 2008 00:27:16 -0000 Author: kmacy Date: Sun Nov 23 00:27:16 2008 New Revision: 185196 URL: http://svn.freebsd.org/changeset/base/185196 Log: - re-enable coalescing by default - remove intr_machdep.h include Modified: user/kmacy/HEAD_fast_multi_xmit/sys/dev/cxgb/cxgb_main.c user/kmacy/HEAD_fast_multi_xmit/sys/dev/cxgb/cxgb_multiq.c Modified: user/kmacy/HEAD_fast_multi_xmit/sys/dev/cxgb/cxgb_main.c ============================================================================== --- user/kmacy/HEAD_fast_multi_xmit/sys/dev/cxgb/cxgb_main.c Sun Nov 23 00:23:58 2008 (r185195) +++ user/kmacy/HEAD_fast_multi_xmit/sys/dev/cxgb/cxgb_main.c Sun Nov 23 00:27:16 2008 (r185196) @@ -82,10 +82,6 @@ __FBSDID("$FreeBSD$"); #include #endif -#ifdef IFNET_MULTIQUEUE -#include -#endif - static int cxgb_setup_msix(adapter_t *, int); static void cxgb_teardown_msix(adapter_t *); static void cxgb_init(void *); Modified: user/kmacy/HEAD_fast_multi_xmit/sys/dev/cxgb/cxgb_multiq.c ============================================================================== --- user/kmacy/HEAD_fast_multi_xmit/sys/dev/cxgb/cxgb_multiq.c Sun Nov 23 00:23:58 2008 (r185195) +++ user/kmacy/HEAD_fast_multi_xmit/sys/dev/cxgb/cxgb_multiq.c Sun Nov 23 00:27:16 2008 (r185196) @@ -88,7 +88,7 @@ __FBSDID("$FreeBSD$"); extern int txq_fills; int multiq_tx_enable = 1; -int coalesce_tx_enable = 0; +int coalesce_tx_enable = 1; int wakeup_tx_thread = 0; extern struct sysctl_oid_list sysctl__hw_cxgb_children; From owner-svn-src-user@FreeBSD.ORG Sun Nov 23 15:04:10 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3EF43106567B; Sun, 23 Nov 2008 15:04:10 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1B3D78FC27; Sun, 23 Nov 2008 15:04:10 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mANF4AB8055045; Sun, 23 Nov 2008 15:04:10 GMT (envelope-from keramida@svn.freebsd.org) Received: (from keramida@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mANF4A25055044; Sun, 23 Nov 2008 15:04:10 GMT (envelope-from keramida@svn.freebsd.org) Message-Id: <200811231504.mANF4A25055044@svn.freebsd.org> From: Giorgos Keramidas Date: Sun, 23 Nov 2008 15:04:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185204 - in user/keramida: . tzcode vendor vendor/tzcode X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Nov 2008 15:04:10 -0000 Author: keramida (doc committer) Date: Sun Nov 23 15:04:09 2008 New Revision: 185204 URL: http://svn.freebsd.org/changeset/base/185204 Log: Add a working area for merging tzcode2008h from the p4 depot. Added: user/keramida/ user/keramida/tzcode/ user/keramida/vendor/ user/keramida/vendor/tzcode/ From owner-svn-src-user@FreeBSD.ORG Sun Nov 23 15:06:04 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 59B48106564A; Sun, 23 Nov 2008 15:06:04 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 359158FC13; Sun, 23 Nov 2008 15:06:04 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mANF64JY055128; Sun, 23 Nov 2008 15:06:04 GMT (envelope-from keramida@svn.freebsd.org) Received: (from keramida@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mANF64mG055127; Sun, 23 Nov 2008 15:06:04 GMT (envelope-from keramida@svn.freebsd.org) Message-Id: <200811231506.mANF64mG055127@svn.freebsd.org> From: Giorgos Keramidas Date: Sun, 23 Nov 2008 15:06:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185205 - user/keramida/vendor/tzcode/dist X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Nov 2008 15:06:04 -0000 Author: keramida (doc committer) Date: Sun Nov 23 15:06:03 2008 New Revision: 185205 URL: http://svn.freebsd.org/changeset/base/185205 Log: Branch tzcode/dist at -r 183403 Added: user/keramida/vendor/tzcode/dist/ - copied from r183403, vendor/tzcode/dist/ From owner-svn-src-user@FreeBSD.ORG Sun Nov 23 15:07:36 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8EAA0106564A; Sun, 23 Nov 2008 15:07:36 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8417E8FC12; Sun, 23 Nov 2008 15:07:36 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mANF7amQ055203; Sun, 23 Nov 2008 15:07:36 GMT (envelope-from keramida@svn.freebsd.org) Received: (from keramida@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mANF7aW4055202; Sun, 23 Nov 2008 15:07:36 GMT (envelope-from keramida@svn.freebsd.org) Message-Id: <200811231507.mANF7aW4055202@svn.freebsd.org> From: Giorgos Keramidas Date: Sun, 23 Nov 2008 15:07:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185206 - user/keramida/vendor/tzcode X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Nov 2008 15:07:36 -0000 Author: keramida (doc committer) Date: Sun Nov 23 15:07:36 2008 New Revision: 185206 URL: http://svn.freebsd.org/changeset/base/185206 Log: Add a FreeBSD-Xlist file for the tzcode2008h import. Added: user/keramida/vendor/tzcode/FreeBSD-Xlist Added: user/keramida/vendor/tzcode/FreeBSD-Xlist ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/keramida/vendor/tzcode/FreeBSD-Xlist Sun Nov 23 15:07:36 2008 (r185206) @@ -0,0 +1,27 @@ +Makefile +checktab.awk +date.1 +date.1.txt +date.c +itca.jpg +newctime.3 +newctime.3.txt +newstrftime.3 +newstrftime.3.txt +newtzset.3 +newtzset.3.txt +time2posix.3.txt +tzfile.5.txt +tzselect.8 +tzselect.8.txt +tzselect.ksh +usno1988 +usno1989 +usno1989a +usno1995 +usno1997 +usno1998 +workman.sh +zdump.8.txt +zic.8.txt +zoneinfo2tdf.pl From owner-svn-src-user@FreeBSD.ORG Sun Nov 23 15:20:40 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C69E61065670; Sun, 23 Nov 2008 15:20:40 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B90AC8FC0C; Sun, 23 Nov 2008 15:20:40 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mANFKetT055515; Sun, 23 Nov 2008 15:20:40 GMT (envelope-from keramida@svn.freebsd.org) Received: (from keramida@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mANFKenN055511; Sun, 23 Nov 2008 15:20:40 GMT (envelope-from keramida@svn.freebsd.org) Message-Id: <200811231520.mANFKenN055511@svn.freebsd.org> From: Giorgos Keramidas Date: Sun, 23 Nov 2008 15:20:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185207 - in user/keramida/vendor/tzcode/dist: libc/stdtime zic X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Nov 2008 15:20:41 -0000 Author: keramida (doc committer) Date: Sun Nov 23 15:20:40 2008 New Revision: 185207 URL: http://svn.freebsd.org/changeset/base/185207 Log: Import the tzcode2008h release. Obtained from: ftp://elsie.nci.nih.gov/pub/tzcode2008h.tar.gz Added: user/keramida/vendor/tzcode/dist/libc/stdtime/time2posix.3 user/keramida/vendor/tzcode/dist/libc/stdtime/tzfile.5 Modified: user/keramida/vendor/tzcode/dist/libc/stdtime/asctime.c user/keramida/vendor/tzcode/dist/libc/stdtime/difftime.c user/keramida/vendor/tzcode/dist/libc/stdtime/localtime.c user/keramida/vendor/tzcode/dist/libc/stdtime/private.h user/keramida/vendor/tzcode/dist/libc/stdtime/strftime.c user/keramida/vendor/tzcode/dist/libc/stdtime/tzfile.h user/keramida/vendor/tzcode/dist/zic/README user/keramida/vendor/tzcode/dist/zic/Theory user/keramida/vendor/tzcode/dist/zic/ialloc.c user/keramida/vendor/tzcode/dist/zic/private.h user/keramida/vendor/tzcode/dist/zic/scheck.c user/keramida/vendor/tzcode/dist/zic/tz-art.htm user/keramida/vendor/tzcode/dist/zic/tz-link.htm user/keramida/vendor/tzcode/dist/zic/zdump.8 user/keramida/vendor/tzcode/dist/zic/zdump.c user/keramida/vendor/tzcode/dist/zic/zic.8 user/keramida/vendor/tzcode/dist/zic/zic.c Modified: user/keramida/vendor/tzcode/dist/libc/stdtime/asctime.c ============================================================================== --- user/keramida/vendor/tzcode/dist/libc/stdtime/asctime.c Sun Nov 23 15:07:36 2008 (r185206) +++ user/keramida/vendor/tzcode/dist/libc/stdtime/asctime.c Sun Nov 23 15:20:40 2008 (r185207) @@ -1,11 +1,17 @@ /* ** This file is in the public domain, so clarified as of -** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). +** 1996-06-05 by Arthur David Olson. +*/ + +/* +** Avoid the temptation to punt entirely to strftime; +** the output of strftime is supposed to be locale specific +** whereas the output of asctime is supposed to be constant. */ #ifndef lint #ifndef NOID -static char elsieid[] = "@(#)asctime.c 7.9"; +static char elsieid[] = "@(#)asctime.c 8.2"; #endif /* !defined NOID */ #endif /* !defined lint */ @@ -15,7 +21,57 @@ static char elsieid[] = "@(#)asctime.c 7 #include "tzfile.h" /* -** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, Second Edition, 1996-07-12. +** Some systems only handle "%.2d"; others only handle "%02d"; +** "%02.2d" makes (most) everybody happy. +** At least some versions of gcc warn about the %02.2d; +** we conditionalize below to avoid the warning. +*/ +/* +** All years associated with 32-bit time_t values are exactly four digits long; +** some years associated with 64-bit time_t values are not. +** Vintage programs are coded for years that are always four digits long +** and may assume that the newline always lands in the same place. +** For years that are less than four digits, we pad the output with +** leading zeroes to get the newline in the traditional place. +** The -4 ensures that we get four characters of output even if +** we call a strftime variant that produces fewer characters for some years. +** The ISO C 1999 and POSIX 1003.1-2004 standards prohibit padding the year, +** but many implementations pad anyway; most likely the standards are buggy. +*/ +#ifdef __GNUC__ +#define ASCTIME_FMT "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %-4s\n" +#else /* !defined __GNUC__ */ +#define ASCTIME_FMT "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %-4s\n" +#endif /* !defined __GNUC__ */ +/* +** For years that are more than four digits we put extra spaces before the year +** so that code trying to overwrite the newline won't end up overwriting +** a digit within a year and truncating the year (operating on the assumption +** that no output is better than wrong output). +*/ +#ifdef __GNUC__ +#define ASCTIME_FMT_B "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %s\n" +#else /* !defined __GNUC__ */ +#define ASCTIME_FMT_B "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %s\n" +#endif /* !defined __GNUC__ */ + +#define STD_ASCTIME_BUF_SIZE 26 +/* +** Big enough for something such as +** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n +** (two three-character abbreviations, five strings denoting integers, +** seven explicit spaces, two explicit colons, a newline, +** and a trailing ASCII nul). +** The values above are for systems where an int is 32 bits and are provided +** as an example; the define below calculates the maximum for the system at +** hand. +*/ +#define MAX_ASCTIME_BUF_SIZE (2*3+5*INT_STRLEN_MAXIMUM(int)+7+2+1+1) + +static char buf_asctime[MAX_ASCTIME_BUF_SIZE]; + +/* +** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, 2004 Edition. */ char * @@ -32,6 +88,8 @@ char * buf; }; register const char * wn; register const char * mn; + char year[INT_STRLEN_MAXIMUM(int) + 2]; + char result[MAX_ASCTIME_BUF_SIZE]; if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK) wn = "???"; @@ -40,35 +98,41 @@ char * buf; mn = "???"; else mn = mon_name[timeptr->tm_mon]; /* - ** The X3J11-suggested format is - ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n" - ** Since the .2 in 02.2d is ignored, we drop it. + ** Use strftime's %Y to generate the year, to avoid overflow problems + ** when computing timeptr->tm_year + TM_YEAR_BASE. + ** Assume that strftime is unaffected by other out-of-range members + ** (e.g., timeptr->tm_mday) when processing "%Y". */ - (void) sprintf(buf, "%.3s %.3s%3d %02d:%02d:%02d %d\n", + (void) strftime(year, sizeof year, "%Y", timeptr); + /* + ** We avoid using snprintf since it's not available on all systems. + */ + (void) sprintf(result, + ((strlen(year) <= 4) ? ASCTIME_FMT : ASCTIME_FMT_B), wn, mn, timeptr->tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec, - TM_YEAR_BASE + timeptr->tm_year); - return buf; + year); + if (strlen(result) < STD_ASCTIME_BUF_SIZE || buf == buf_asctime) { + (void) strcpy(buf, result); + return buf; + } else { +#ifdef EOVERFLOW + errno = EOVERFLOW; +#else /* !defined EOVERFLOW */ + errno = EINVAL; +#endif /* !defined EOVERFLOW */ + return NULL; + } } /* -** A la X3J11, with core dump avoidance. +** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, 2004 Edition. */ char * asctime(timeptr) register const struct tm * timeptr; { - /* - ** Big enough for something such as - ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n - ** (two three-character abbreviations, five strings denoting integers, - ** three explicit spaces, two explicit colons, a newline, - ** and a trailing ASCII nul). - */ - static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + - 3 + 2 + 1 + 1]; - - return asctime_r(timeptr, result); + return asctime_r(timeptr, buf_asctime); } Modified: user/keramida/vendor/tzcode/dist/libc/stdtime/difftime.c ============================================================================== --- user/keramida/vendor/tzcode/dist/libc/stdtime/difftime.c Sun Nov 23 15:07:36 2008 (r185206) +++ user/keramida/vendor/tzcode/dist/libc/stdtime/difftime.c Sun Nov 23 15:20:40 2008 (r185207) @@ -1,83 +1,65 @@ /* ** This file is in the public domain, so clarified as of -** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). +** 1996-06-05 by Arthur David Olson. */ #ifndef lint #ifndef NOID -static char elsieid[] = "@(#)difftime.c 7.9"; +static char elsieid[] = "@(#)difftime.c 8.1"; #endif /* !defined NOID */ #endif /* !defined lint */ /*LINTLIBRARY*/ -#include "private.h" - -/* -** Algorithm courtesy Paul Eggert (eggert@twinsun.com). -*/ - -#ifdef HAVE_LONG_DOUBLE -#define long_double long double -#endif /* defined HAVE_LONG_DOUBLE */ -#ifndef HAVE_LONG_DOUBLE -#define long_double double -#endif /* !defined HAVE_LONG_DOUBLE */ +#include "private.h" /* for time_t, TYPE_INTEGRAL, and TYPE_SIGNED */ double difftime(time1, time0) const time_t time1; const time_t time0; { - time_t delta; - time_t hibit; - - { - time_t tt; - double d; - long_double ld; - - if (sizeof tt < sizeof d) - return (double) time1 - (double) time0; - if (sizeof tt < sizeof ld) - return (long_double) time1 - (long_double) time0; + /* + ** If (sizeof (double) > sizeof (time_t)) simply convert and subtract + ** (assuming that the larger type has more precision). + ** This is the common real-world case circa 2004. + */ + if (sizeof (double) > sizeof (time_t)) + return (double) time1 - (double) time0; + if (!TYPE_INTEGRAL(time_t)) { + /* + ** time_t is floating. + */ + return time1 - time0; + } + if (!TYPE_SIGNED(time_t)) { + /* + ** time_t is integral and unsigned. + ** The difference of two unsigned values can't overflow + ** if the minuend is greater than or equal to the subtrahend. + */ + if (time1 >= time0) + return time1 - time0; + else return -((double) (time0 - time1)); } - if (time1 < time0) - return -difftime(time0, time1); /* - ** As much as possible, avoid loss of precision - ** by computing the difference before converting to double. + ** time_t is integral and signed. + ** Handle cases where both time1 and time0 have the same sign + ** (meaning that their difference cannot overflow). */ - delta = time1 - time0; - if (delta >= 0) - return delta; + if ((time1 < 0) == (time0 < 0)) + return time1 - time0; /* - ** Repair delta overflow. + ** time1 and time0 have opposite signs. + ** Punt if unsigned long is too narrow. */ - hibit = (~ (time_t) 0) << (TYPE_BIT(time_t) - 1); + if (sizeof (unsigned long) < sizeof (time_t)) + return (double) time1 - (double) time0; /* - ** The following expression rounds twice, which means - ** the result may not be the closest to the true answer. - ** For example, suppose time_t is 64-bit signed int, - ** long_double is IEEE 754 double with default rounding, - ** time1 = 9223372036854775807 and time0 = -1536. - ** Then the true difference is 9223372036854777343, - ** which rounds to 9223372036854777856 - ** with a total error of 513. - ** But delta overflows to -9223372036854774273, - ** which rounds to -9223372036854774784, and correcting - ** this by subtracting 2 * (long_double) hibit - ** (i.e. by adding 2**64 = 18446744073709551616) - ** yields 9223372036854776832, which - ** rounds to 9223372036854775808 - ** with a total error of 1535 instead. - ** This problem occurs only with very large differences. - ** It's too painful to fix this portably. - ** We are not alone in this problem; - ** some C compilers round twice when converting - ** large unsigned types to small floating types, - ** so if time_t is unsigned the "return delta" above - ** has the same double-rounding problem with those compilers. + ** Stay calm...decent optimizers will eliminate the complexity below. */ - return delta - 2 * (long_double) hibit; + if (time1 >= 0 /* && time0 < 0 */) + return (unsigned long) time1 + + (unsigned long) (-(time0 + 1)) + 1; + return -(double) ((unsigned long) time0 + + (unsigned long) (-(time1 + 1)) + 1); } Modified: user/keramida/vendor/tzcode/dist/libc/stdtime/localtime.c ============================================================================== --- user/keramida/vendor/tzcode/dist/libc/stdtime/localtime.c Sun Nov 23 15:07:36 2008 (r185206) +++ user/keramida/vendor/tzcode/dist/libc/stdtime/localtime.c Sun Nov 23 15:20:40 2008 (r185207) @@ -1,18 +1,17 @@ /* ** This file is in the public domain, so clarified as of -** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). +** 1996-06-05 by Arthur David Olson. */ #ifndef lint #ifndef NOID -static char elsieid[] = "@(#)localtime.c 7.78"; +static char elsieid[] = "@(#)localtime.c 8.9"; #endif /* !defined NOID */ #endif /* !defined lint */ /* -** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu). -** POSIX-style TZ environment variable handling from Guy Harris -** (guy@auspex.com). +** Leap second handling from Bradley White. +** POSIX-style TZ environment variable handling from Guy Harris. */ /*LINTLIBRARY*/ @@ -20,6 +19,20 @@ static char elsieid[] = "@(#)localtime.c #include "private.h" #include "tzfile.h" #include "fcntl.h" +#include "float.h" /* for FLT_MAX and DBL_MAX */ + +#ifndef TZ_ABBR_MAX_LEN +#define TZ_ABBR_MAX_LEN 16 +#endif /* !defined TZ_ABBR_MAX_LEN */ + +#ifndef TZ_ABBR_CHAR_SET +#define TZ_ABBR_CHAR_SET \ + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 :+-._" +#endif /* !defined TZ_ABBR_CHAR_SET */ + +#ifndef TZ_ABBR_ERR_CHAR +#define TZ_ABBR_ERR_CHAR '_' +#endif /* !defined TZ_ABBR_ERR_CHAR */ /* ** SunOS 4.1.1 headers lack O_BINARY. @@ -46,16 +59,16 @@ static char elsieid[] = "@(#)localtime.c ** 5. They might reference tm.TM_ZONE after calling offtime. ** What's best to do in the above cases is open to debate; ** for now, we just set things up so that in any of the five cases -** WILDABBR is used. Another possibility: initialize tzname[0] to the +** WILDABBR is used. Another possibility: initialize tzname[0] to the ** string "tzname[0] used before set", and similarly for the other cases. -** And another: initialize tzname[0] to "ERA", with an explanation in the +** And another: initialize tzname[0] to "ERA", with an explanation in the ** manual page of what this "time zone abbreviation" means (doing this so ** that tzname[0] has the "normal" length of three characters). */ #define WILDABBR " " #endif /* !defined WILDABBR */ -static char wildabbr[] = "WILDABBR"; +static char wildabbr[] = WILDABBR; static const char gmt[] = "GMT"; @@ -97,6 +110,8 @@ struct state { int timecnt; int typecnt; int charcnt; + int goback; + int goahead; time_t ats[TZ_MAX_TIMES]; unsigned char types[TZ_MAX_TIMES]; struct ttinfo ttis[TZ_MAX_TYPES]; @@ -121,43 +136,52 @@ struct rule { ** Prototypes for static functions. */ -static long detzcode P((const char * codep)); -static const char * getzname P((const char * strp)); -static const char * getnum P((const char * strp, int * nump, int min, - int max)); -static const char * getsecs P((const char * strp, long * secsp)); -static const char * getoffset P((const char * strp, long * offsetp)); -static const char * getrule P((const char * strp, struct rule * rulep)); -static void gmtload P((struct state * sp)); -static void gmtsub P((const time_t * timep, long offset, - struct tm * tmp)); -static void localsub P((const time_t * timep, long offset, - struct tm * tmp)); -static int increment_overflow P((int * number, int delta)); -static int normalize_overflow P((int * tensptr, int * unitsptr, - int base)); -static void settzname P((void)); -static time_t time1 P((struct tm * tmp, - void(*funcp) P((const time_t *, - long, struct tm *)), - long offset)); -static time_t time2 P((struct tm *tmp, - void(*funcp) P((const time_t *, - long, struct tm*)), - long offset, int * okayp)); -static time_t time2sub P((struct tm *tmp, - void(*funcp) P((const time_t *, - long, struct tm*)), - long offset, int * okayp, int do_norm_secs)); -static void timesub P((const time_t * timep, long offset, - const struct state * sp, struct tm * tmp)); -static int tmcomp P((const struct tm * atmp, - const struct tm * btmp)); -static time_t transtime P((time_t janfirst, int year, - const struct rule * rulep, long offset)); -static int tzload P((const char * name, struct state * sp)); -static int tzparse P((const char * name, struct state * sp, - int lastditch)); +static long detzcode(const char * codep); +static time_t detzcode64(const char * codep); +static int differ_by_repeat(time_t t1, time_t t0); +static const char * getzname(const char * strp); +static const char * getqzname(const char * strp, const int delim); +static const char * getnum(const char * strp, int * nump, int min, + int max); +static const char * getsecs(const char * strp, long * secsp); +static const char * getoffset(const char * strp, long * offsetp); +static const char * getrule(const char * strp, struct rule * rulep); +static void gmtload(struct state * sp); +static struct tm * gmtsub(const time_t * timep, long offset, + struct tm * tmp); +static struct tm * localsub(const time_t * timep, long offset, + struct tm * tmp); +static int increment_overflow(int * number, int delta); +static int leaps_thru_end_of(int y); +static int long_increment_overflow(long * number, int delta); +static int long_normalize_overflow(long * tensptr, + int * unitsptr, int base); +static int normalize_overflow(int * tensptr, int * unitsptr, + int base); +static void settzname(void); +static time_t time1(struct tm * tmp, + struct tm * (*funcp)(const time_t *, + long, struct tm *), + long offset); +static time_t time2(struct tm *tmp, + struct tm * (*funcp)(const time_t *, + long, struct tm*), + long offset, int * okayp); +static time_t time2sub(struct tm *tmp, + struct tm * (*funcp)(const time_t *, + long, struct tm*), + long offset, int * okayp, int do_norm_secs); +static struct tm * timesub(const time_t * timep, long offset, + const struct state * sp, struct tm * tmp); +static int tmcomp(const struct tm * atmp, + const struct tm * btmp); +static time_t transtime(time_t janfirst, int year, + const struct rule * rulep, long offset); +static int typesequiv(const struct state * sp, int a, int b); +static int tzload(const char * name, struct state * sp, + int doextend); +static int tzparse(const char * name, struct state * sp, + int lastditch); #ifdef ALL_STATE static struct state * lclptr; @@ -189,7 +213,7 @@ char * tzname[2] = { ** Except for the strftime function, these functions [asctime, ** ctime, gmtime, localtime] return values in one of two static ** objects: a broken-down time structure and an array of char. -** Thanks to Paul Eggert (eggert@twinsun.com) for noting this. +** Thanks to Paul Eggert for noting this. */ static struct tm tm; @@ -210,14 +234,27 @@ const char * const codep; register long result; register int i; - result = (codep[0] & 0x80) ? ~0L : 0L; + result = (codep[0] & 0x80) ? ~0L : 0; for (i = 0; i < 4; ++i) result = (result << 8) | (codep[i] & 0xff); return result; } +static time_t +detzcode64(codep) +const char * const codep; +{ + register time_t result; + register int i; + + result = (codep[0] & 0x80) ? (~(int_fast64_t) 0) : 0; + for (i = 0; i < 8; ++i) + result = result * 256 + (codep[i] & 0xff); + return result; +} + static void -settzname P((void)) +settzname(void) { register struct state * const sp = lclptr; register int i; @@ -264,16 +301,54 @@ settzname P((void)) tzname[ttisp->tt_isdst] = &sp->chars[ttisp->tt_abbrind]; } + /* + ** Finally, scrub the abbreviations. + ** First, replace bogus characters. + */ + for (i = 0; i < sp->charcnt; ++i) + if (strchr(TZ_ABBR_CHAR_SET, sp->chars[i]) == NULL) + sp->chars[i] = TZ_ABBR_ERR_CHAR; + /* + ** Second, truncate long abbreviations. + */ + for (i = 0; i < sp->typecnt; ++i) { + register const struct ttinfo * const ttisp = &sp->ttis[i]; + register char * cp = &sp->chars[ttisp->tt_abbrind]; + + if (strlen(cp) > TZ_ABBR_MAX_LEN && + strcmp(cp, GRANDPARENTED) != 0) + *(cp + TZ_ABBR_MAX_LEN) = '\0'; + } } static int -tzload(name, sp) +differ_by_repeat(t1, t0) +const time_t t1; +const time_t t0; +{ + if (TYPE_INTEGRAL(time_t) && + TYPE_BIT(time_t) - TYPE_SIGNED(time_t) < SECSPERREPEAT_BITS) + return 0; + return t1 - t0 == SECSPERREPEAT; +} + +static int +tzload(name, sp, doextend) register const char * name; register struct state * const sp; +register const int doextend; { - register const char * p; - register int i; - register int fid; + register const char * p; + register int i; + register int fid; + register int stored; + register int nread; + union { + struct tzhead tzhead; + char buf[2 * sizeof(struct tzhead) + + 2 * sizeof *sp + + 4 * TZ_MAX_TIMES]; + } u; if (name == NULL && (name = TZDEFAULT) == NULL) return -1; @@ -311,18 +386,13 @@ register struct state * const sp; if ((fid = open(name, OPEN_MODE)) == -1) return -1; } - { - struct tzhead * tzhp; - union { - struct tzhead tzhead; - char buf[sizeof *sp + sizeof *tzhp]; - } u; + nread = read(fid, u.buf, sizeof u.buf); + if (close(fid) < 0 || nread <= 0) + return -1; + for (stored = 4; stored <= 8; stored *= 2) { int ttisstdcnt; int ttisgmtcnt; - i = read(fid, u.buf, sizeof u.buf); - if (close(fid) != 0) - return -1; ttisstdcnt = (int) detzcode(u.tzhead.tzh_ttisstdcnt); ttisgmtcnt = (int) detzcode(u.tzhead.tzh_ttisgmtcnt); sp->leapcnt = (int) detzcode(u.tzhead.tzh_leapcnt); @@ -337,17 +407,19 @@ register struct state * const sp; (ttisstdcnt != sp->typecnt && ttisstdcnt != 0) || (ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0)) return -1; - if (i - (p - u.buf) < sp->timecnt * 4 + /* ats */ + if (nread - (p - u.buf) < + sp->timecnt * stored + /* ats */ sp->timecnt + /* types */ - sp->typecnt * (4 + 2) + /* ttinfos */ + sp->typecnt * 6 + /* ttinfos */ sp->charcnt + /* chars */ - sp->leapcnt * (4 + 4) + /* lsinfos */ + sp->leapcnt * (stored + 4) + /* lsinfos */ ttisstdcnt + /* ttisstds */ ttisgmtcnt) /* ttisgmts */ return -1; for (i = 0; i < sp->timecnt; ++i) { - sp->ats[i] = detzcode(p); - p += 4; + sp->ats[i] = (stored == 4) ? + detzcode(p) : detzcode64(p); + p += stored; } for (i = 0; i < sp->timecnt; ++i) { sp->types[i] = (unsigned char) *p++; @@ -375,8 +447,9 @@ register struct state * const sp; register struct lsinfo * lsisp; lsisp = &sp->lsis[i]; - lsisp->ls_trans = detzcode(p); - p += 4; + lsisp->ls_trans = (stored == 4) ? + detzcode(p) : detzcode64(p); + p += stored; lsisp->ls_corr = detzcode(p); p += 4; } @@ -406,10 +479,127 @@ register struct state * const sp; return -1; } } + /* + ** Out-of-sort ats should mean we're running on a + ** signed time_t system but using a data file with + ** unsigned values (or vice versa). + */ + for (i = 0; i < sp->timecnt - 2; ++i) + if (sp->ats[i] > sp->ats[i + 1]) { + ++i; + if (TYPE_SIGNED(time_t)) { + /* + ** Ignore the end (easy). + */ + sp->timecnt = i; + } else { + /* + ** Ignore the beginning (harder). + */ + register int j; + + for (j = 0; j + i < sp->timecnt; ++j) { + sp->ats[j] = sp->ats[j + i]; + sp->types[j] = sp->types[j + i]; + } + sp->timecnt = j; + } + break; + } + /* + ** If this is an old file, we're done. + */ + if (u.tzhead.tzh_version[0] == '\0') + break; + nread -= p - u.buf; + for (i = 0; i < nread; ++i) + u.buf[i] = p[i]; + /* + ** If this is a narrow integer time_t system, we're done. + */ + if (stored >= (int) sizeof(time_t) && TYPE_INTEGRAL(time_t)) + break; + } + if (doextend && nread > 2 && + u.buf[0] == '\n' && u.buf[nread - 1] == '\n' && + sp->typecnt + 2 <= TZ_MAX_TYPES) { + struct state ts; + register int result; + + u.buf[nread - 1] = '\0'; + result = tzparse(&u.buf[1], &ts, FALSE); + if (result == 0 && ts.typecnt == 2 && + sp->charcnt + ts.charcnt <= TZ_MAX_CHARS) { + for (i = 0; i < 2; ++i) + ts.ttis[i].tt_abbrind += + sp->charcnt; + for (i = 0; i < ts.charcnt; ++i) + sp->chars[sp->charcnt++] = + ts.chars[i]; + i = 0; + while (i < ts.timecnt && + ts.ats[i] <= + sp->ats[sp->timecnt - 1]) + ++i; + while (i < ts.timecnt && + sp->timecnt < TZ_MAX_TIMES) { + sp->ats[sp->timecnt] = + ts.ats[i]; + sp->types[sp->timecnt] = + sp->typecnt + + ts.types[i]; + ++sp->timecnt; + ++i; + } + sp->ttis[sp->typecnt++] = ts.ttis[0]; + sp->ttis[sp->typecnt++] = ts.ttis[1]; + } + } + sp->goback = sp->goahead = FALSE; + if (sp->timecnt > 1) { + for (i = 1; i < sp->timecnt; ++i) + if (typesequiv(sp, sp->types[i], sp->types[0]) && + differ_by_repeat(sp->ats[i], sp->ats[0])) { + sp->goback = TRUE; + break; + } + for (i = sp->timecnt - 2; i >= 0; --i) + if (typesequiv(sp, sp->types[sp->timecnt - 1], + sp->types[i]) && + differ_by_repeat(sp->ats[sp->timecnt - 1], + sp->ats[i])) { + sp->goahead = TRUE; + break; + } } return 0; } +static int +typesequiv(sp, a, b) +const struct state * const sp; +const int a; +const int b; +{ + register int result; + + if (sp == NULL || + a < 0 || a >= sp->typecnt || + b < 0 || b >= sp->typecnt) + result = FALSE; + else { + register const struct ttinfo * ap = &sp->ttis[a]; + register const struct ttinfo * bp = &sp->ttis[b]; + result = ap->tt_gmtoff == bp->tt_gmtoff && + ap->tt_isdst == bp->tt_isdst && + ap->tt_ttisstd == bp->tt_ttisstd && + ap->tt_ttisgmt == bp->tt_ttisgmt && + strcmp(&sp->chars[ap->tt_abbrind], + &sp->chars[bp->tt_abbrind]) == 0; + } + return result; +} + static const int mon_lengths[2][MONSPERYEAR] = { { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } @@ -421,7 +611,7 @@ static const int year_lengths[2] = { /* ** Given a pointer into a time zone string, scan until a character that is not -** a valid character in a zone name is found. Return a pointer to that +** a valid character in a zone name is found. Return a pointer to that ** character. */ @@ -438,6 +628,25 @@ register const char * strp; } /* +** Given a pointer into an extended time zone string, scan until the ending +** delimiter of the zone name is located. Return a pointer to the delimiter. +** +** As with getzname above, the legal character set is actually quite +** restricted, with other characters producing undefined results. +** We don't do any checking here; checking is done later in common-case code. +*/ + +static const char * +getqzname(register const char *strp, const int delim) +{ + register int c; + + while ((c = *strp) != '\0' && c != delim) + ++strp; + return strp; +} + +/* ** Given a pointer into a time zone string, extract a number from that string. ** Check that the number is within a specified range; if it is not, return ** NULL. @@ -502,7 +711,7 @@ long * const secsp; *secsp += num * SECSPERMIN; if (*strp == ':') { ++strp; - /* `SECSPERMIN' allows for leap seconds. */ + /* `SECSPERMIN' allows for leap seconds. */ strp = getnum(strp, &num, 0, SECSPERMIN); if (strp == NULL) return NULL; @@ -541,7 +750,7 @@ long * const offsetp; /* ** Given a pointer into a time zone string, extract a rule in the form -** date[/time]. See POSIX section 8 for the format of "date" and "time". +** date[/time]. See POSIX section 8 for the format of "date" and "time". ** If a valid rule is not found, return NULL. ** Otherwise, return a pointer to the first character not part of the rule. */ @@ -660,7 +869,7 @@ const long offset; dow += DAYSPERWEEK; /* - ** "dow" is the day-of-week of the first day of the month. Get + ** "dow" is the day-of-week of the first day of the month. Get ** the day-of-month (zero-origin) of the first "dow" day of the ** month. */ @@ -683,7 +892,7 @@ const long offset; /* ** "value" is the Epoch-relative time of 00:00:00 UTC on the day in - ** question. To get the Epoch-relative time of the specified local + ** question. To get the Epoch-relative time of the specified local ** time on that day, add the transition time and the current offset ** from UTC. */ @@ -721,25 +930,40 @@ const int lastditch; stdlen = (sizeof sp->chars) - 1; stdoffset = 0; } else { - name = getzname(name); - stdlen = name - stdname; - if (stdlen < 3) - return -1; + if (*name == '<') { + name++; + stdname = name; + name = getqzname(name, '>'); + if (*name != '>') + return (-1); + stdlen = name - stdname; + name++; + } else { + name = getzname(name); + stdlen = name - stdname; + } if (*name == '\0') return -1; name = getoffset(name, &stdoffset); if (name == NULL) return -1; } - load_result = tzload(TZDEFRULES, sp); + load_result = tzload(TZDEFRULES, sp, FALSE); if (load_result != 0) sp->leapcnt = 0; /* so, we're off a little */ if (*name != '\0') { - dstname = name; - name = getzname(name); - dstlen = name - dstname; /* length of DST zone name */ - if (dstlen < 3) - return -1; + if (*name == '<') { + dstname = ++name; + name = getqzname(name, '>'); + if (*name != '>') + return -1; + dstlen = name - dstname; + name++; + } else { + dstname = name; + name = getzname(name); + dstlen = name - dstname; /* length of DST zone name */ + } if (*name != '\0' && *name != ',' && *name != ';') { name = getoffset(name, &dstoffset); if (name == NULL) @@ -766,11 +990,8 @@ const int lastditch; return -1; sp->typecnt = 2; /* standard time and DST */ /* - ** Two transitions per year, from EPOCH_YEAR to 2037. + ** Two transitions per year, from EPOCH_YEAR forward. */ - sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1); - if (sp->timecnt > TZ_MAX_TIMES) - return -1; sp->ttis[0].tt_gmtoff = -dstoffset; sp->ttis[0].tt_isdst = 1; sp->ttis[0].tt_abbrind = stdlen + 1; @@ -780,7 +1001,12 @@ const int lastditch; atp = sp->ats; typep = sp->types; janfirst = 0; - for (year = EPOCH_YEAR; year <= 2037; ++year) { + sp->timecnt = 0; + for (year = EPOCH_YEAR; + sp->timecnt + 2 <= TZ_MAX_TIMES; + ++year) { + time_t newfirst; + starttime = transtime(janfirst, year, &start, stdoffset); endtime = transtime(janfirst, year, &end, @@ -796,8 +1022,13 @@ const int lastditch; *atp++ = endtime; *typep++ = 1; /* DST ends */ } - janfirst += year_lengths[isleap(year)] * + sp->timecnt += 2; + newfirst = janfirst; + newfirst += year_lengths[isleap(year)] * SECSPERDAY; + if (newfirst <= janfirst) + break; + janfirst = newfirst; } } else { register long theirstdoffset; @@ -912,7 +1143,7 @@ static void gmtload(sp) struct state * const sp; { - if (tzload(gmt, sp) != 0) + if (tzload(gmt, sp, TRUE) != 0) (void) tzparse(gmt, sp, TRUE); } @@ -924,7 +1155,7 @@ struct state * const sp; static #endif /* !defined STD_INSPIRED */ void -tzsetwall P((void)) +tzsetwall(void) { if (lcl_is_set < 0) return; @@ -939,13 +1170,13 @@ tzsetwall P((void)) } } #endif /* defined ALL_STATE */ - if (tzload((char *) NULL, lclptr) != 0) + if (tzload((char *) NULL, lclptr, TRUE) != 0) gmtload(lclptr); settzname(); } void -tzset P((void)) +tzset(void) { register const char * name; @@ -981,7 +1212,7 @@ tzset P((void)) lclptr->ttis[0].tt_gmtoff = 0; lclptr->ttis[0].tt_abbrind = 0; (void) strcpy(lclptr->chars, gmt); - } else if (tzload(name, lclptr) != 0) + } else if (tzload(name, lclptr, TRUE) != 0) if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0) (void) gmtload(lclptr); settzname(); @@ -990,14 +1221,14 @@ tzset P((void)) /* ** The easy way to behave "as if no library function calls" localtime ** is to not call it--so we drop its guts into "localsub", which can be -** freely called. (And no, the PANS doesn't require the above behavior-- +** freely called. (And no, the PANS doesn't require the above behavior-- ** but it *is* desirable.) ** ** The unused offset argument is for the benefit of mktime variants. */ /*ARGSUSED*/ -static void +static struct tm * localsub(timep, offset, tmp) const time_t * const timep; const long offset; @@ -1006,15 +1237,53 @@ struct tm * const tmp; register struct state * sp; register const struct ttinfo * ttisp; register int i; + register struct tm * result; const time_t t = *timep; sp = lclptr; #ifdef ALL_STATE - if (sp == NULL) { - gmtsub(timep, offset, tmp); - return; - } + if (sp == NULL) + return gmtsub(timep, offset, tmp); #endif /* defined ALL_STATE */ + if ((sp->goback && t < sp->ats[0]) || + (sp->goahead && t > sp->ats[sp->timecnt - 1])) { + time_t newt = t; + register time_t seconds; + register time_t tcycles; + register int_fast64_t icycles; + + if (t < sp->ats[0]) + seconds = sp->ats[0] - t; + else seconds = t - sp->ats[sp->timecnt - 1]; + --seconds; + tcycles = seconds / YEARSPERREPEAT / AVGSECSPERYEAR; + ++tcycles; + icycles = tcycles; + if (tcycles - icycles >= 1 || icycles - tcycles >= 1) + return NULL; + seconds = icycles; + seconds *= YEARSPERREPEAT; + seconds *= AVGSECSPERYEAR; + if (t < sp->ats[0]) + newt += seconds; + else newt -= seconds; + if (newt < sp->ats[0] || + newt > sp->ats[sp->timecnt - 1]) + return NULL; /* "cannot happen" */ + result = localsub(&newt, offset, tmp); + if (result == tmp) { + register time_t newy; + + newy = tmp->tm_year; + if (t < sp->ats[0]) + newy -= icycles * YEARSPERREPEAT; + else newy += icycles * YEARSPERREPEAT; *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-user@FreeBSD.ORG Sun Nov 23 15:27:00 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0F9A41065692; Sun, 23 Nov 2008 15:27:00 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DE64B8FC1B; Sun, 23 Nov 2008 15:26:59 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mANFQxGm055706; Sun, 23 Nov 2008 15:26:59 GMT (envelope-from keramida@svn.freebsd.org) Received: (from keramida@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mANFQxH4055705; Sun, 23 Nov 2008 15:26:59 GMT (envelope-from keramida@svn.freebsd.org) Message-Id: <200811231526.mANFQxH4055705@svn.freebsd.org> From: Giorgos Keramidas Date: Sun, 23 Nov 2008 15:26:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185208 - in user/keramida/tzcode: libc zic X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Nov 2008 15:27:00 -0000 Author: keramida (doc committer) Date: Sun Nov 23 15:26:59 2008 New Revision: 185208 URL: http://svn.freebsd.org/changeset/base/185208 Log: Branch the tzcode/dist vendor code @ 185205 before the tzcode2008h import, to start merging the FreeBSD-specific changes on top of it. Added: user/keramida/tzcode/libc/ - copied from r185205, user/keramida/vendor/tzcode/dist/libc/ user/keramida/tzcode/zic/ - copied from r185205, user/keramida/vendor/tzcode/dist/zic/ From owner-svn-src-user@FreeBSD.ORG Sun Nov 23 16:06:42 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1BB6D1065677; Sun, 23 Nov 2008 16:06:42 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0C1168FC0A; Sun, 23 Nov 2008 16:06:42 +0000 (UTC) (envelope-from keramida@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mANG6gjX056543; Sun, 23 Nov 2008 16:06:42 GMT (envelope-from keramida@svn.freebsd.org) Received: (from keramida@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mANG6f62056535; Sun, 23 Nov 2008 16:06:41 GMT (envelope-from keramida@svn.freebsd.org) Message-Id: <200811231606.mANG6f62056535@svn.freebsd.org> From: Giorgos Keramidas Date: Sun, 23 Nov 2008 16:06:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185209 - in user/keramida/tzcode: libc/stdtime zic zic/zdump zic/zic X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Nov 2008 16:06:42 -0000 Author: keramida (doc committer) Date: Sun Nov 23 16:06:41 2008 New Revision: 185209 URL: http://svn.freebsd.org/changeset/base/185209 Log: Merge FreeBSD-specific changes and bootstrap mergeinfo from /head. Added: user/keramida/tzcode/libc/stdtime/Makefile.inc - copied unchanged from r185208, head/lib/libc/stdtime/Makefile.inc user/keramida/tzcode/libc/stdtime/Symbol.map - copied unchanged from r185208, head/lib/libc/stdtime/Symbol.map user/keramida/tzcode/libc/stdtime/ctime.3 - copied unchanged from r185208, head/lib/libc/stdtime/ctime.3 user/keramida/tzcode/libc/stdtime/strftime.3 - copied unchanged from r185208, head/lib/libc/stdtime/strftime.3 user/keramida/tzcode/libc/stdtime/strptime.3 - copied unchanged from r185208, head/lib/libc/stdtime/strptime.3 user/keramida/tzcode/libc/stdtime/strptime.c - copied unchanged from r185208, head/lib/libc/stdtime/strptime.c user/keramida/tzcode/libc/stdtime/time32.c - copied unchanged from r185208, head/lib/libc/stdtime/time32.c user/keramida/tzcode/libc/stdtime/timelocal.c - copied unchanged from r185208, head/lib/libc/stdtime/timelocal.c user/keramida/tzcode/libc/stdtime/timelocal.h - copied unchanged from r185208, head/lib/libc/stdtime/timelocal.h user/keramida/tzcode/zic/Arts.htm - copied unchanged from r185208, head/usr.sbin/zic/Arts.htm user/keramida/tzcode/zic/Makefile - copied unchanged from r185208, head/usr.sbin/zic/Makefile user/keramida/tzcode/zic/Makefile.inc - copied unchanged from r185208, head/usr.sbin/zic/Makefile.inc user/keramida/tzcode/zic/zdump/ - copied from r185208, head/usr.sbin/zic/zdump/ user/keramida/tzcode/zic/zic/ - copied from r185208, head/usr.sbin/zic/zic/ Modified: user/keramida/tzcode/libc/stdtime/ (props changed) user/keramida/tzcode/libc/stdtime/asctime.c user/keramida/tzcode/libc/stdtime/difftime.c user/keramida/tzcode/libc/stdtime/localtime.c user/keramida/tzcode/libc/stdtime/private.h user/keramida/tzcode/libc/stdtime/strftime.c user/keramida/tzcode/libc/stdtime/tzfile.h user/keramida/tzcode/zic/ (props changed) user/keramida/tzcode/zic/ialloc.c user/keramida/tzcode/zic/private.h user/keramida/tzcode/zic/scheck.c user/keramida/tzcode/zic/zdump.8 user/keramida/tzcode/zic/zdump.c user/keramida/tzcode/zic/zic.8 user/keramida/tzcode/zic/zic.c Copied: user/keramida/tzcode/libc/stdtime/Makefile.inc (from r185208, head/lib/libc/stdtime/Makefile.inc) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/keramida/tzcode/libc/stdtime/Makefile.inc Sun Nov 23 16:06:41 2008 (r185209, copy of r185208, head/lib/libc/stdtime/Makefile.inc) @@ -0,0 +1,18 @@ +# Makefile.inc,v 1.2 1994/09/13 21:26:01 wollman Exp +# $FreeBSD$ + +.PATH: ${.CURDIR}/stdtime ${.CURDIR}/../locale + +SRCS+= asctime.c difftime.c localtime.c strftime.c strptime.c timelocal.c \ + time32.c + +SYM_MAPS+= ${.CURDIR}/stdtime/Symbol.map + +MAN+= ctime.3 strftime.3 strptime.3 time2posix.3 +MAN+= tzfile.5 + +MLINKS+=ctime.3 asctime.3 ctime.3 difftime.3 ctime.3 gmtime.3 \ + ctime.3 localtime.3 ctime.3 mktime.3 ctime.3 timegm.3 \ + ctime.3 ctime_r.3 ctime.3 localtime_r.3 ctime.3 gmtime_r.3 \ + ctime.3 asctime_r.3 +MLINKS+=time2posix.3 posix2time.3 Copied: user/keramida/tzcode/libc/stdtime/Symbol.map (from r185208, head/lib/libc/stdtime/Symbol.map) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/keramida/tzcode/libc/stdtime/Symbol.map Sun Nov 23 16:06:41 2008 (r185209, copy of r185208, head/lib/libc/stdtime/Symbol.map) @@ -0,0 +1,35 @@ +/* + * $FreeBSD$ + */ + +FBSD_1.0 { + _time32_to_time; + _time_to_time32; + _time64_to_time; + _time_to_time64; + _time_to_long; + _long_to_time; + _time_to_int; + _int_to_time; + strptime; + strftime; + tzname; + tzsetwall; + tzset; + localtime; + localtime_r; + gmtime; + gmtime_r; + offtime; + ctime; + ctime_r; + mktime; + timelocal; + timegm; + timeoff; + time2posix; + posix2time; + difftime; + asctime_r; + asctime; +}; Modified: user/keramida/tzcode/libc/stdtime/asctime.c ============================================================================== --- user/keramida/tzcode/libc/stdtime/asctime.c Sun Nov 23 15:26:59 2008 (r185208) +++ user/keramida/tzcode/libc/stdtime/asctime.c Sun Nov 23 16:06:41 2008 (r185209) @@ -3,15 +3,19 @@ ** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). */ +#include #ifndef lint #ifndef NOID -static char elsieid[] = "@(#)asctime.c 7.9"; +static char elsieid[] __unused = "@(#)asctime.c 7.9"; #endif /* !defined NOID */ #endif /* !defined lint */ +__FBSDID("$FreeBSD$"); /*LINTLIBRARY*/ +#include "namespace.h" #include "private.h" +#include "un-namespace.h" #include "tzfile.h" /* @@ -20,8 +24,8 @@ static char elsieid[] = "@(#)asctime.c 7 char * asctime_r(timeptr, buf) -register const struct tm * timeptr; -char * buf; +const struct tm * timeptr; +char * buf; { static const char wday_name[][3] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" @@ -30,8 +34,8 @@ char * buf; "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - register const char * wn; - register const char * mn; + const char * wn; + const char * mn; if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK) wn = "???"; @@ -58,7 +62,7 @@ char * buf; char * asctime(timeptr) -register const struct tm * timeptr; +const struct tm * timeptr; { /* ** Big enough for something such as Copied: user/keramida/tzcode/libc/stdtime/ctime.3 (from r185208, head/lib/libc/stdtime/ctime.3) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/keramida/tzcode/libc/stdtime/ctime.3 Sun Nov 23 16:06:41 2008 (r185209, copy of r185208, head/lib/libc/stdtime/ctime.3) @@ -0,0 +1,374 @@ +.\" Copyright (c) 1989, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" Arthur Olson. +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" From: @(#)ctime.3 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD$ +.\" +.Dd January 2, 1999 +.Dt CTIME 3 +.Os +.Sh NAME +.Nm asctime , +.Nm asctime_r , +.Nm ctime , +.Nm ctime_r , +.Nm difftime , +.Nm gmtime , +.Nm gmtime_r , +.Nm localtime , +.Nm localtime_r , +.Nm mktime , +.Nm timegm +.Nd transform binary date and time values +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In time.h +.Vt extern char *tzname[2] ; +.Ft char * +.Fn ctime "const time_t *clock" +.Ft double +.Fn difftime "time_t time1" "time_t time0" +.Ft char * +.Fn asctime "const struct tm *tm" +.Ft struct tm * +.Fn localtime "const time_t *clock" +.Ft struct tm * +.Fn gmtime "const time_t *clock" +.Ft time_t +.Fn mktime "struct tm *tm" +.Ft time_t +.Fn timegm "struct tm *tm" +.Ft char * +.Fn ctime_r "const time_t *clock" "char *buf" +.Ft struct tm * +.Fn localtime_r "const time_t *clock" "struct tm *result" +.Ft struct tm * +.Fn gmtime_r "const time_t *clock" "struct tm *result" +.Ft char * +.Fn asctime_r "const struct tm *tm" "char *buf" +.Sh DESCRIPTION +The functions +.Fn ctime , +.Fn gmtime +and +.Fn localtime +all take as an argument a time value representing the time in seconds since +the Epoch (00:00:00 +.Tn UTC , +January 1, 1970; see +.Xr time 3 ) . +.Pp +The function +.Fn localtime +converts the time value pointed at by +.Fa clock , +and returns a pointer to a +.Dq Fa struct tm +(described below) which contains +the broken-out time information for the value after adjusting for the current +time zone (and any other factors such as Daylight Saving Time). +Time zone adjustments are performed as specified by the +.Ev TZ +environment variable (see +.Xr tzset 3 ) . +The function +.Fn localtime +uses +.Xr tzset 3 +to initialize time conversion information if +.Xr tzset 3 +has not already been called by the process. +.Pp +After filling in the tm structure, +.Fn localtime +sets the +.Fa tm_isdst Ns 'th +element of +.Fa tzname +to a pointer to an +.Tn ASCII +string that is the time zone abbreviation to be +used with +.Fn localtime Ns 's +return value. +.Pp +The function +.Fn gmtime +similarly converts the time value, but without any time zone adjustment, +and returns a pointer to a tm structure (described below). +.Pp +The +.Fn ctime +function +adjusts the time value for the current time zone in the same manner as +.Fn localtime , +and returns a pointer to a 26-character string of the form: +.Bd -literal -offset indent +Thu Nov 24 18:22:48 1986\en\e0 +.Ed +.Pp +All the fields have constant width. +.Pp +The +.Fn ctime_r +function +provides the same functionality as +.Fn ctime +except the caller must provide the output buffer +.Fa buf +to store the result, which must be at least 26 characters long. +The +.Fn localtime_r +and +.Fn gmtime_r +functions +provide the same functionality as +.Fn localtime +and +.Fn gmtime +respectively, except the caller must provide the output buffer +.Fa result . +.Pp +The +.Fn asctime +function +converts the broken down time in the structure +.Fa tm +pointed at by +.Fa *tm +to the form +shown in the example above. +.Pp +The +.Fn asctime_r +function +provides the same functionality as +.Fn asctime +except the caller provide the output buffer +.Fa buf +to store the result, which must be at least 26 characters long. +.Pp +The functions +.Fn mktime +and +.Fn timegm +convert the broken-down time in the structure +pointed to by tm into a time value with the same encoding as that of the +values returned by the +.Xr time 3 +function (that is, seconds from the Epoch, +.Tn UTC ) . +The +.Fn mktime +function +interprets the input structure according to the current timezone setting +(see +.Xr tzset 3 ) . +The +.Fn timegm +function +interprets the input structure as representing Universal Coordinated Time +.Pq Tn UTC . +.Pp +The original values of the +.Fa tm_wday +and +.Fa tm_yday +components of the structure are ignored, and the original values of the +other components are not restricted to their normal ranges, and will be +normalized if needed. +For example, +October 40 is changed into November 9, +a +.Fa tm_hour +of \-1 means 1 hour before midnight, +.Fa tm_mday +of 0 means the day preceding the current month, and +.Fa tm_mon +of \-2 means 2 months before January of +.Fa tm_year . +(A positive or zero value for +.Fa tm_isdst +causes +.Fn mktime +to presume initially that summer time (for example, Daylight Saving Time) +is or is not in effect for the specified time, respectively. +A negative value for +.Fa tm_isdst +causes the +.Fn mktime +function to attempt to divine whether summer time is in effect for the +specified time. +The +.Fa tm_isdst +and +.Fa tm_gmtoff +members are forced to zero by +.Fn timegm . ) +.Pp +On successful completion, the values of the +.Fa tm_wday +and +.Fa tm_yday +components of the structure are set appropriately, and the other components +are set to represent the specified calendar time, but with their values +forced to their normal ranges; the final value of +.Fa tm_mday +is not set until +.Fa tm_mon +and +.Fa tm_year +are determined. +The +.Fn mktime +function +returns the specified calendar time; if the calendar time cannot be +represented, it returns \-1; +.Pp +The +.Fn difftime +function +returns the difference between two calendar times, +.Pf ( Fa time1 +- +.Fa time0 ) , +expressed in seconds. +.Pp +External declarations as well as the tm structure definition are in the +.In time.h +include file. +The tm structure includes at least the following fields: +.Bd -literal -offset indent +int tm_sec; /\(** seconds (0 - 60) \(**/ +int tm_min; /\(** minutes (0 - 59) \(**/ +int tm_hour; /\(** hours (0 - 23) \(**/ +int tm_mday; /\(** day of month (1 - 31) \(**/ +int tm_mon; /\(** month of year (0 - 11) \(**/ +int tm_year; /\(** year \- 1900 \(**/ +int tm_wday; /\(** day of week (Sunday = 0) \(**/ +int tm_yday; /\(** day of year (0 - 365) \(**/ +int tm_isdst; /\(** is summer time in effect? \(**/ +char \(**tm_zone; /\(** abbreviation of timezone name \(**/ +long tm_gmtoff; /\(** offset from UTC in seconds \(**/ +.Ed +.Pp +The +field +.Fa tm_isdst +is non-zero if summer time is in effect. +.Pp +The field +.Fa tm_gmtoff +is the offset (in seconds) of the time represented from +.Tn UTC , +with positive +values indicating east of the Prime Meridian. +.Sh SEE ALSO +.Xr date 1 , +.Xr gettimeofday 2 , +.Xr getenv 3 , +.Xr time 3 , +.Xr tzset 3 , +.Xr tzfile 5 +.Sh STANDARDS +The +.Fn asctime , +.Fn ctime , +.Fn difftime , +.Fn gmtime , +.Fn localtime , +and +.Fn mktime +functions conform to +.St -isoC , +and conform to +.St -p1003.1-96 +provided the selected local timezone does not contain a leap-second table +(see +.Xr zic 8 ) . +.Pp +The +.Fn asctime_r , +.Fn ctime_r , +.Fn gmtime_r , +and +.Fn localtime_r +functions are expected to conform to +.St -p1003.1-96 +(again provided the selected local timezone does not contain a leap-second +table). +.Pp +The +.Fn timegm +function is not specified by any standard; its function cannot be +completely emulated using the standard functions described above. +.Sh HISTORY +This manual page is derived from +the time package contributed to Berkeley by +.An Arthur Olson +and which appeared in +.Bx 4.3 . +.Sh BUGS +Except for +.Fn difftime , +.Fn mktime , +and the +.Fn \&_r +variants of the other functions, +these functions leaves their result in an internal static object and return +a pointer to that object. +Subsequent calls to these +function will modify the same object. +.Pp +The C Standard provides no mechanism for a program to modify its current +local timezone setting, and the +.Tn POSIX Ns No \&-standard +method is not reentrant. +(However, thread-safe implementations are provided +in the +.Tn POSIX +threaded environment.) +.Pp +The +.Va tm_zone +field of a returned +.Vt tm +structure points to a static array of characters, +which will also be overwritten by any subsequent calls (as well as by +subsequent calls to +.Xr tzset 3 +and +.Xr tzsetwall 3 ) . +.Pp +Use of the external variable +.Fa tzname +is discouraged; the +.Fa tm_zone +entry in the tm structure is preferred. Modified: user/keramida/tzcode/libc/stdtime/difftime.c ============================================================================== --- user/keramida/tzcode/libc/stdtime/difftime.c Sun Nov 23 15:26:59 2008 (r185208) +++ user/keramida/tzcode/libc/stdtime/difftime.c Sun Nov 23 16:06:41 2008 (r185209) @@ -3,15 +3,19 @@ ** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). */ +#include #ifndef lint #ifndef NOID -static char elsieid[] = "@(#)difftime.c 7.9"; +static char elsieid[] __unused = "@(#)difftime.c 7.9"; #endif /* !defined NOID */ #endif /* !defined lint */ +__FBSDID("$FreeBSD$"); /*LINTLIBRARY*/ +#include "namespace.h" #include "private.h" +#include "un-namespace.h" /* ** Algorithm courtesy Paul Eggert (eggert@twinsun.com). Modified: user/keramida/tzcode/libc/stdtime/localtime.c ============================================================================== --- user/keramida/tzcode/libc/stdtime/localtime.c Sun Nov 23 15:26:59 2008 (r185208) +++ user/keramida/tzcode/libc/stdtime/localtime.c Sun Nov 23 16:06:41 2008 (r185209) @@ -3,11 +3,13 @@ ** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). */ +#include #ifndef lint #ifndef NOID -static char elsieid[] = "@(#)localtime.c 7.78"; +static char elsieid[] __unused = "@(#)localtime.c 7.78"; #endif /* !defined NOID */ #endif /* !defined lint */ +__FBSDID("$FreeBSD$"); /* ** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu). @@ -17,9 +19,35 @@ static char elsieid[] = "@(#)localtime.c /*LINTLIBRARY*/ +#include "namespace.h" +#include +#include +#include +#include #include "private.h" +#include "un-namespace.h" + #include "tzfile.h" -#include "fcntl.h" + +#include "libc_private.h" + +#define _MUTEX_LOCK(x) if (__isthreaded) _pthread_mutex_lock(x) +#define _MUTEX_UNLOCK(x) if (__isthreaded) _pthread_mutex_unlock(x) + +#define _RWLOCK_RDLOCK(x) \ + do { \ + if (__isthreaded) _pthread_rwlock_rdlock(x); \ + } while (0) + +#define _RWLOCK_WRLOCK(x) \ + do { \ + if (__isthreaded) _pthread_rwlock_wrlock(x); \ + } while (0) + +#define _RWLOCK_UNLOCK(x) \ + do { \ + if (__isthreaded) _pthread_rwlock_unlock(x); \ + } while (0) /* ** SunOS 4.1.1 headers lack O_BINARY. @@ -57,7 +85,12 @@ static char elsieid[] = "@(#)localtime.c static char wildabbr[] = "WILDABBR"; -static const char gmt[] = "GMT"; +/* + * In June 2004 it was decided UTC was a more appropriate default time + * zone than GMT. + */ + +static const char gmt[] = "UTC"; /* ** The DST rules to use if TZ has no rules and we can't load TZDEFRULES. @@ -121,43 +154,43 @@ struct rule { ** Prototypes for static functions. */ -static long detzcode P((const char * codep)); -static const char * getzname P((const char * strp)); -static const char * getnum P((const char * strp, int * nump, int min, - int max)); -static const char * getsecs P((const char * strp, long * secsp)); -static const char * getoffset P((const char * strp, long * offsetp)); -static const char * getrule P((const char * strp, struct rule * rulep)); -static void gmtload P((struct state * sp)); -static void gmtsub P((const time_t * timep, long offset, - struct tm * tmp)); -static void localsub P((const time_t * timep, long offset, - struct tm * tmp)); -static int increment_overflow P((int * number, int delta)); -static int normalize_overflow P((int * tensptr, int * unitsptr, - int base)); -static void settzname P((void)); -static time_t time1 P((struct tm * tmp, - void(*funcp) P((const time_t *, - long, struct tm *)), - long offset)); -static time_t time2 P((struct tm *tmp, - void(*funcp) P((const time_t *, - long, struct tm*)), - long offset, int * okayp)); -static time_t time2sub P((struct tm *tmp, - void(*funcp) P((const time_t *, - long, struct tm*)), - long offset, int * okayp, int do_norm_secs)); -static void timesub P((const time_t * timep, long offset, - const struct state * sp, struct tm * tmp)); -static int tmcomp P((const struct tm * atmp, - const struct tm * btmp)); -static time_t transtime P((time_t janfirst, int year, - const struct rule * rulep, long offset)); -static int tzload P((const char * name, struct state * sp)); -static int tzparse P((const char * name, struct state * sp, - int lastditch)); +static long detzcode(const char * codep); +static const char * getzname(const char * strp); +static const char * getnum(const char * strp, int * nump, int min, + int max); +static const char * getsecs(const char * strp, long * secsp); +static const char * getoffset(const char * strp, long * offsetp); +static const char * getrule(const char * strp, struct rule * rulep); +static void gmtload(struct state * sp); +static void gmtsub(const time_t * timep, long offset, + struct tm * tmp); +static void localsub(const time_t * timep, long offset, + struct tm * tmp); +static int increment_overflow(int * number, int delta); +static int normalize_overflow(int * tensptr, int * unitsptr, + int base); +static void settzname(void); +static time_t time1(struct tm * tmp, + void(*funcp) (const time_t *, + long, struct tm *), + long offset); +static time_t time2(struct tm *tmp, + void(*funcp) (const time_t *, + long, struct tm*), + long offset, int * okayp); +static time_t time2sub(struct tm *tmp, + void(*funcp) (const time_t *, + long, struct tm*), + long offset, int * okayp, int do_norm_secs); +static void timesub(const time_t * timep, long offset, + const struct state * sp, struct tm * tmp); +static int tmcomp(const struct tm * atmp, + const struct tm * btmp); +static time_t transtime(time_t janfirst, int year, + const struct rule * rulep, long offset); +static int tzload(const char * name, struct state * sp); +static int tzparse(const char * name, struct state * sp, + int lastditch); #ifdef ALL_STATE static struct state * lclptr; @@ -178,6 +211,8 @@ static struct state gmtmem; static char lcl_TZname[TZ_STRLEN_MAX + 1]; static int lcl_is_set; static int gmt_is_set; +static pthread_rwlock_t lcl_rwlock = PTHREAD_RWLOCK_INITIALIZER; +static pthread_mutex_t gmt_mutex = PTHREAD_MUTEX_INITIALIZER; char * tzname[2] = { wildabbr, @@ -207,8 +242,8 @@ static long detzcode(codep) const char * const codep; { - register long result; - register int i; + long result; + int i; result = (codep[0] & 0x80) ? ~0L : 0L; for (i = 0; i < 4; ++i) @@ -217,10 +252,10 @@ const char * const codep; } static void -settzname P((void)) +settzname(void) { - register struct state * const sp = lclptr; - register int i; + struct state * sp = lclptr; + int i; tzname[0] = wildabbr; tzname[1] = wildabbr; @@ -238,7 +273,7 @@ settzname P((void)) } #endif /* defined ALL_STATE */ for (i = 0; i < sp->typecnt; ++i) { - register const struct ttinfo * const ttisp = &sp->ttis[i]; + const struct ttinfo * const ttisp = &sp->ttis[i]; tzname[ttisp->tt_isdst] = &sp->chars[ttisp->tt_abbrind]; @@ -257,7 +292,7 @@ settzname P((void)) ** And to get the latest zone names into tzname. . . */ for (i = 0; i < sp->timecnt; ++i) { - register const struct ttinfo * const ttisp = + const struct ttinfo * const ttisp = &sp->ttis[ sp->types[i]]; @@ -268,17 +303,23 @@ settzname P((void)) static int tzload(name, sp) -register const char * name; -register struct state * const sp; +const char * name; +struct state * const sp; { - register const char * p; - register int i; - register int fid; - + const char * p; + int i; + int fid; + + /* XXX The following is from OpenBSD, and I'm not sure it is correct */ + if (name != NULL && issetugid() != 0) + if ((name[0] == ':' && name[1] == '/') || + name[0] == '/' || strchr(name, '.')) + name = NULL; if (name == NULL && (name = TZDEFAULT) == NULL) return -1; { - register int doaccess; + int doaccess; + struct stat stab; /* ** Section 4.9.1 of the C standard says that ** "FILENAME_MAX expands to an integral constant expression @@ -294,7 +335,7 @@ register struct state * const sp; if (!doaccess) { if ((p = TZDIR) == NULL) return -1; - if ((strlen(p) + strlen(name) + 1) >= sizeof fullname) + if ((strlen(p) + 1 + strlen(name) + 1) >= sizeof fullname) return -1; (void) strcpy(fullname, p); (void) strcat(fullname, "/"); @@ -307,9 +348,13 @@ register struct state * const sp; name = fullname; } if (doaccess && access(name, R_OK) != 0) + return -1; + if ((fid = _open(name, OPEN_MODE)) == -1) return -1; - if ((fid = open(name, OPEN_MODE)) == -1) + if ((_fstat(fid, &stab) < 0) || !S_ISREG(stab.st_mode)) { + _close(fid); return -1; + } } { struct tzhead * tzhp; @@ -320,8 +365,8 @@ register struct state * const sp; int ttisstdcnt; int ttisgmtcnt; - i = read(fid, u.buf, sizeof u.buf); - if (close(fid) != 0) + i = _read(fid, u.buf, sizeof u.buf); + if (_close(fid) != 0) return -1; ttisstdcnt = (int) detzcode(u.tzhead.tzh_ttisstdcnt); ttisgmtcnt = (int) detzcode(u.tzhead.tzh_ttisgmtcnt); @@ -355,7 +400,7 @@ register struct state * const sp; return -1; } for (i = 0; i < sp->typecnt; ++i) { - register struct ttinfo * ttisp; + struct ttinfo * ttisp; ttisp = &sp->ttis[i]; ttisp->tt_gmtoff = detzcode(p); @@ -372,7 +417,7 @@ register struct state * const sp; sp->chars[i] = *p++; sp->chars[i] = '\0'; /* ensure '\0' at end */ for (i = 0; i < sp->leapcnt; ++i) { - register struct lsinfo * lsisp; + struct lsinfo * lsisp; lsisp = &sp->lsis[i]; lsisp->ls_trans = detzcode(p); @@ -381,7 +426,7 @@ register struct state * const sp; p += 4; } for (i = 0; i < sp->typecnt; ++i) { - register struct ttinfo * ttisp; + struct ttinfo * ttisp; ttisp = &sp->ttis[i]; if (ttisstdcnt == 0) @@ -394,7 +439,7 @@ register struct state * const sp; } } for (i = 0; i < sp->typecnt; ++i) { - register struct ttinfo * ttisp; + struct ttinfo * ttisp; ttisp = &sp->ttis[i]; if (ttisgmtcnt == 0) @@ -427,9 +472,9 @@ static const int year_lengths[2] = { static const char * getzname(strp) -register const char * strp; +const char * strp; { - register char c; + char c; while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' && c != '+') @@ -446,13 +491,13 @@ register const char * strp; static const char * getnum(strp, nump, min, max) -register const char * strp; +const char * strp; int * const nump; const int min; const int max; { - register char c; - register int num; + char c; + int num; if (strp == NULL || !is_digit(c = *strp)) return NULL; @@ -479,7 +524,7 @@ const int max; static const char * getsecs(strp, secsp) -register const char * strp; +const char * strp; long * const secsp; { int num; @@ -521,10 +566,10 @@ long * const secsp; static const char * getoffset(strp, offsetp) -register const char * strp; +const char * strp; long * const offsetp; { - register int neg = 0; + int neg = 0; if (*strp == '-') { neg = 1; @@ -549,7 +594,7 @@ long * const offsetp; static const char * getrule(strp, rulep) const char * strp; -register struct rule * const rulep; +struct rule * const rulep; { if (*strp == 'J') { /* @@ -604,12 +649,12 @@ static time_t transtime(janfirst, year, rulep, offset) const time_t janfirst; const int year; -register const struct rule * const rulep; +const struct rule * const rulep; const long offset; { - register int leapyear; - register time_t value; - register int i; + int leapyear; + time_t value; + int i; int d, m1, yy0, yy1, yy2, dow; INITIALIZE(value); @@ -698,7 +743,7 @@ const long offset; static int tzparse(name, sp, lastditch) const char * name; -register struct state * const sp; +struct state * const sp; const int lastditch; { const char * stdname; @@ -707,10 +752,10 @@ const int lastditch; size_t dstlen; long stdoffset; long dstoffset; - register time_t * atp; - register unsigned char * typep; - register char * cp; - register int load_result; + time_t * atp; + unsigned char * typep; + char * cp; + int load_result; INITIALIZE(dstname); stdname = name; @@ -726,10 +771,12 @@ const int lastditch; if (stdlen < 3) return -1; if (*name == '\0') - return -1; - name = getoffset(name, &stdoffset); - if (name == NULL) - return -1; + return -1; /* was "stdoffset = 0;" */ + else { + name = getoffset(name, &stdoffset); + if (name == NULL) + return -1; + } } load_result = tzload(TZDEFRULES, sp); if (load_result != 0) @@ -750,8 +797,8 @@ const int lastditch; if (*name == ',' || *name == ';') { struct rule start; struct rule end; - register int year; - register time_t janfirst; + int year; + time_t janfirst; time_t starttime; time_t endtime; @@ -800,12 +847,12 @@ const int lastditch; SECSPERDAY; } } else { - register long theirstdoffset; - register long theirdstoffset; - register long theiroffset; - register int isdst; - register int i; - register int j; + long theirstdoffset; + long theirdstoffset; + long theiroffset; + int isdst; + int i; + int j; if (*name != '\0') return -1; @@ -916,18 +963,19 @@ struct state * const sp; (void) tzparse(gmt, sp, TRUE); } -#ifndef STD_INSPIRED -/* -** A non-static declaration of tzsetwall in a system header file -** may cause a warning about this upcoming static declaration... -*/ -static -#endif /* !defined STD_INSPIRED */ -void -tzsetwall P((void)) +static void +tzsetwall_basic(int rdlocked) { - if (lcl_is_set < 0) + if (!rdlocked) + _RWLOCK_RDLOCK(&lcl_rwlock); + if (lcl_is_set < 0) { + if (!rdlocked) + _RWLOCK_UNLOCK(&lcl_rwlock); return; + } + _RWLOCK_UNLOCK(&lcl_rwlock); + + _RWLOCK_WRLOCK(&lcl_rwlock); lcl_is_set = -1; #ifdef ALL_STATE @@ -935,6 +983,9 @@ tzsetwall P((void)) lclptr = (struct state *) malloc(sizeof *lclptr); if (lclptr == NULL) { settzname(); /* all we can do */ + _RWLOCK_UNLOCK(&lcl_rwlock); + if (rdlocked) *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-user@FreeBSD.ORG Tue Nov 25 13:33:19 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1928D106567B; Tue, 25 Nov 2008 13:33:19 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0998E8FC1F; Tue, 25 Nov 2008 13:33:19 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mAPDXIOk023644; Tue, 25 Nov 2008 13:33:18 GMT (envelope-from netchild@svn.freebsd.org) Received: (from netchild@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mAPDXIsa023642; Tue, 25 Nov 2008 13:33:18 GMT (envelope-from netchild@svn.freebsd.org) Message-Id: <200811251333.mAPDXIsa023642@svn.freebsd.org> From: Alexander Leidinger Date: Tue, 25 Nov 2008 13:33:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185294 - in user/netchild/linuxulator-dtrace: . src src/sys src/sys/amd64 src/sys/amd64/linux32 src/sys/compat src/sys/compat/linprocfs src/sys/compat/linsysfs src/sys/compat/linux src... X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Nov 2008 13:33:19 -0000 Author: netchild Date: Tue Nov 25 13:33:18 2008 New Revision: 185294 URL: http://svn.freebsd.org/changeset/base/185294 Log: Baseline for static dtrace probes in linuxulator. Added: user/netchild/linuxulator-dtrace/ user/netchild/linuxulator-dtrace/DESIGN user/netchild/linuxulator-dtrace/README user/netchild/linuxulator-dtrace/src/ user/netchild/linuxulator-dtrace/src/sys/ user/netchild/linuxulator-dtrace/src/sys/amd64/ user/netchild/linuxulator-dtrace/src/sys/amd64/linux32/ (props changed) - copied from r185293, head/sys/amd64/linux32/ user/netchild/linuxulator-dtrace/src/sys/compat/ user/netchild/linuxulator-dtrace/src/sys/compat/linprocfs/ (props changed) - copied from r185293, head/sys/compat/linprocfs/ user/netchild/linuxulator-dtrace/src/sys/compat/linsysfs/ (props changed) - copied from r185293, head/sys/compat/linsysfs/ user/netchild/linuxulator-dtrace/src/sys/compat/linux/ (props changed) - copied from r185293, head/sys/compat/linux/ user/netchild/linuxulator-dtrace/src/sys/i386/ user/netchild/linuxulator-dtrace/src/sys/i386/linux/ (props changed) - copied from r185293, head/sys/i386/linux/ Added: user/netchild/linuxulator-dtrace/DESIGN ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/netchild/linuxulator-dtrace/DESIGN Tue Nov 25 13:33:18 2008 (r185294) @@ -0,0 +1,10 @@ +This file contains some design decissions for various things in this branch. + + - Add probes only for locks which are acquired in one functions and released + in another function. Locks which are aquired and released in the same + function should be easy to pair in the code, wheras inter-function + locking is better checked in dtrace. + - Probes for locks should be fired after locking and before releasing to + prevent races (to provide data/function stability in dtrace, see the + output of "dtrace -v ..." and the corresponding dtrace docs). + Added: user/netchild/linuxulator-dtrace/README ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/netchild/linuxulator-dtrace/README Tue Nov 25 13:33:18 2008 (r185294) @@ -0,0 +1 @@ +Branch to add some static dtrace probes into the linuxulator. From owner-svn-src-user@FreeBSD.ORG Tue Nov 25 13:52:02 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 921661065670; Tue, 25 Nov 2008 13:52:02 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8340E8FC2D; Tue, 25 Nov 2008 13:52:02 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mAPDq2Jb025193; Tue, 25 Nov 2008 13:52:02 GMT (envelope-from netchild@svn.freebsd.org) Received: (from netchild@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mAPDq29x025190; Tue, 25 Nov 2008 13:52:02 GMT (envelope-from netchild@svn.freebsd.org) Message-Id: <200811251352.mAPDq29x025190@svn.freebsd.org> From: Alexander Leidinger Date: Tue, 25 Nov 2008 13:52:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185296 - in user/netchild/linuxulator-dtrace/src/sys: amd64/linux32 compat/linux i386/linux X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Nov 2008 13:52:02 -0000 Author: netchild Date: Tue Nov 25 13:52:02 2008 New Revision: 185296 URL: http://svn.freebsd.org/changeset/base/185296 Log: Commit what I started yesterday (first few static dtrace probes in the linuxulator). Beware, this is WIP, this is not even compile tested. Modified: user/netchild/linuxulator-dtrace/src/sys/amd64/linux32/linux.h user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_emul.c user/netchild/linuxulator-dtrace/src/sys/i386/linux/linux.h Modified: user/netchild/linuxulator-dtrace/src/sys/amd64/linux32/linux.h ============================================================================== --- user/netchild/linuxulator-dtrace/src/sys/amd64/linux32/linux.h Tue Nov 25 13:35:06 2008 (r185295) +++ user/netchild/linuxulator-dtrace/src/sys/amd64/linux32/linux.h Tue Nov 25 13:52:02 2008 (r185296) @@ -42,6 +42,7 @@ extern u_char linux_debug_map[]; #define ldebug(name) isclr(linux_debug_map, LINUX_SYS_linux_ ## name) #define ARGS(nm, fmt) "linux(%ld): "#nm"("fmt")\n", (long)td->td_proc->p_pid #define LMSG(fmt) "linux(%ld): "fmt"\n", (long)td->td_proc->p_pid +#define LINUX_DTRACE linuxulator32 #ifdef MALLOC_DECLARE MALLOC_DECLARE(M_LINUX); Modified: user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_emul.c ============================================================================== --- user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_emul.c Tue Nov 25 13:35:06 2008 (r185295) +++ user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_emul.c Tue Nov 25 13:52:02 2008 (r185296) @@ -30,6 +30,8 @@ __FBSDID("$FreeBSD$"); #include "opt_compat.h" +#include "opt_kdtrace.h" +#include "opt_ktrace.h" #include #include @@ -38,11 +40,15 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include #include #include +#ifdef KTRACE +#include +#endif #ifdef COMPAT_LINUX32 #include @@ -55,6 +61,55 @@ __FBSDID("$FreeBSD$"); #include #include +/* + * In this file we define the provider for the entire linuxulator. All + * modules (= files of the linuxulator) use it. + * + * We define a different name depending on the emulated bitsize, see + * ../..//linux*/linux.h, e.g.: + * native bitsize = linuxulator + * amd64, 32bit emulation = linuxulator32 + */ +SDT_PROVIDER_DEFINE(LINUX_DTRACE); + +/* DTrace probes in this module. */ +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, em_find, entry); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, em_find, entry, 0, "struct proc *"); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, em_find, entry, 1, "int"); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, em_find, emul_locked); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, em_find, emul_locked, 0, "struct mtx *"); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, em_find, emul_unlock); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, em_find, emul_unlock, 0, "struct mtx *"); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, em_find, return); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, em_find, return, 0, + "struct linux_emuldata *"); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_init, entry); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_init, entry, 0, "struct thread *"); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_init, entry, 1, "pid_t"); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_init, entry, 2, "int"); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_init, emul_unlock); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_init, emul_unlock, 0, + "struct mtx *"); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_init, return); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exit, entry); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exit, entry, 0, "struct proc *"); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exit, emul_unlock); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exit, emul_unlock, 0, + "struct mtx *"); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exit, reparent); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exit, reparent, 0, "pid_t"); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exit, reparent, 1, "pid_t"); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exit, reparent, 2, "struct proc *"); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exit, child_clear_tid_error); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exit, child_clear_tid_error, 0, + "int"); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exit, return); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exec, entry); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exec, entry, 0, "struct proc *"); +SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exec, entry, 0, + "struct image_params *"); +SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exec, return); + struct sx emul_shared_lock; struct mtx emul_lock; @@ -64,14 +119,23 @@ em_find(struct proc *p, int locked) { struct linux_emuldata *em; - if (locked == EMUL_DOLOCK) + SDT_PROBE(LINUX_DTRACE, emul, em_find, entry, p, locked, 0, 0, 0); + + if (locked == EMUL_DOLOCK) { EMUL_LOCK(&emul_lock); + SDT_PROBE(LINUX_DTRACE, emul, em_find, emul_lock, &emul_lock, + 0, 0, 0, 0); + } em = p->p_emuldata; - if (em == NULL && locked == EMUL_DOLOCK) + if (em == NULL && locked == EMUL_DOLOCK) { + SDT_PROBE(LINUX_DTRACE, emul, em_find, emul_unlock, &emul_lock, + 0, 0, 0, 0); EMUL_UNLOCK(&emul_lock); + } + SDT_PROBE(LINUX_DTRACE, emul, em_find, return, em, 0, 0, 0, 0); return (em); } @@ -81,17 +145,25 @@ linux_proc_init(struct thread *td, pid_t struct linux_emuldata *em, *p_em; struct proc *p; + SDT_PROBE(LINUX_DTRACE, emul, proc_init, entry, td, child, flags, 0, 0); + if (child != 0) { - /* non-exec call */ + /* fork or create a thread */ + em = malloc(sizeof *em, M_LINUX, M_WAITOK | M_ZERO); em->pid = child; em->pdeath_signal = 0; em->robust_futexes = NULL; if (flags & LINUX_CLONE_THREAD) { /* handled later in the code */ + SDT_PROBE(LINUX_DTRACE, emul, proc_init, create_thread, + 0, 0, 0, 0, 0); } else { struct linux_emuldata_shared *s; + SDT_PROBE(LINUX_DTRACE, emul, proc_init, fork, 0, 0, 0, + 0, 0); + s = malloc(sizeof *s, M_LINUX, M_WAITOK | M_ZERO); s->refs = 1; s->group_pid = child; @@ -100,6 +172,10 @@ linux_proc_init(struct thread *td, pid_t em->shared = s; } } else { + /* exec */ + + SDT_PROBE(LINUX_DTRACE, emul, proc_init, exec, 0, 0, 0, 0, 0); + /* lookup the old one */ em = em_find(td->td_proc, EMUL_DOLOCK); KASSERT(em != NULL, ("proc_init: emuldata not found in exec case.\n")); @@ -134,8 +210,7 @@ linux_proc_init(struct thread *td, pid_t * rwlock held */ } - } - if (child != 0) { + EMUL_SHARED_WLOCK(&emul_shared_lock); LIST_INSERT_HEAD(&em->shared->threads, em, threads); EMUL_SHARED_WUNLOCK(&emul_shared_lock); @@ -144,9 +219,13 @@ linux_proc_init(struct thread *td, pid_t KASSERT(p != NULL, ("process not found in proc_init\n")); p->p_emuldata = em; PROC_UNLOCK(p); - } else + } else { + SDT_PROBE(LINUX_DTRACE, emul, proc_init, emul_unlock, + &emul_lock, 0, 0, 0, 0); EMUL_UNLOCK(&emul_lock); + } + SDT_PROBE(LINUX_DTRACE, emul, proc_init, return, 0, 0, 0, 0, 0); return (0); } @@ -162,17 +241,25 @@ linux_proc_exit(void *arg __unused, stru if (__predict_true(p->p_sysent != &elf_linux_sysvec)) return; + SDT_PROBE(LINUX_DTRACE, emul, proc_exit, entry, p, 0, 0, 0, 0); + release_futexes(p); /* find the emuldata */ em = em_find(p, EMUL_DOLOCK); - KASSERT(em != NULL, ("proc_exit: emuldata not found.\n")); /* reparent all procs that are not a thread leader to initproc */ if (em->shared->group_pid != p->p_pid) { + SDT_PROBE(LINUX_DTRACE, emul, proc_exit, reparent, + em->shared->group_pid, p->p_pid, p, 0, 0); + child_clear_tid = em->child_clear_tid; + + SDT_PROBE(LINUX_DTRACE, emul, proc_exit, emul_unlock, + &emul_lock, 0, 0, 0, 0); EMUL_UNLOCK(&emul_lock); + sx_xlock(&proctree_lock); wakeup(initproc); PROC_LOCK(p); @@ -182,6 +269,9 @@ linux_proc_exit(void *arg __unused, stru sx_xunlock(&proctree_lock); } else { child_clear_tid = em->child_clear_tid; + + SDT_PROBE(LINUX_DTRACE, emul, proc_exit, emul_unlock, + &emul_lock, 0, 0, 0, 0); EMUL_UNLOCK(&emul_lock); } @@ -201,7 +291,13 @@ linux_proc_exit(void *arg __unused, stru error = copyout(&null, child_clear_tid, sizeof(null)); if (error) { + SDT_PROBE(LINUX_DTRACE, emul, proc_exit, + child_clear_tid_error, error, 0, 0, 0, 0); + free(em, M_LINUX); + + SDT_PROBE(LINUX_DTRACE, emul, proc_exit, return, 0, 0, + 0, 0, 0); return; } @@ -217,8 +313,11 @@ linux_proc_exit(void *arg __unused, stru * this cannot happen at the moment and if this happens it * probably means there is a user space bug */ - if (error) + if (error) { + SDT_PROBE(LINUX_DTRACE, emul, proc_exit, futex_failed, + 0, 0, 0, 0, 0); printf(LMSG("futex stuff in proc_exit failed.\n")); + } } /* clean the stuff up */ @@ -240,9 +339,13 @@ linux_proc_exit(void *arg __unused, stru psignal(q, em->pdeath_signal); } PROC_UNLOCK(q); + SDT_PROBE(LINUX_DTRACE, emul, proc_exit, emul_unlock, + &emul_lock, 0, 0, 0, 0); EMUL_UNLOCK(&emul_lock); } sx_xunlock(&proctree_lock); + + SDT_PROBE(LINUX_DTRACE, emul, proc_exit, return, 0, 0, 0, 0, 0); } /* @@ -253,38 +356,44 @@ linux_proc_exit(void *arg __unused, stru void linux_proc_exec(void *arg __unused, struct proc *p, struct image_params *imgp) { - if (__predict_false(imgp->sysent == &elf_linux_sysvec - && p->p_sysent != &elf_linux_sysvec)) - linux_proc_init(FIRST_THREAD_IN_PROC(p), p->p_pid, 0); - if (__predict_false(imgp->sysent != &elf_linux_sysvec - && p->p_sysent == &elf_linux_sysvec)) { - struct linux_emuldata *em; - - /* - * XXX:There's a race because here we assign p->p_emuldata NULL - * but the process is still counted as linux one for a short - * time so some other process might reference it and try to - * access its p->p_emuldata and panicing on a NULL reference. - */ - em = em_find(p, EMUL_DONTLOCK); + if (__predict_false(imgp->sysent == &elf_linux_sysvec) { + SDT_PROBE(LINUX_DTRACE, emul, proc_exec, entry, p, imgp, 0, 0, + 0); + + if (p->p_sysent != &elf_linux_sysvec)) + linux_proc_init(FIRST_THREAD_IN_PROC(p), p->p_pid, 0); + else { + struct linux_emuldata *em; - KASSERT(em != NULL, ("proc_exec: emuldata not found.\n")); + /* + * XXX:There's a race because here we assign + * p->p_emuldata NULL but the process is still counted + * as linux one for a short time so some other process + * might reference it and try to access its + * p->p_emuldata and panicing on a NULL reference. + */ + em = em_find(p, EMUL_DONTLOCK); + KASSERT(em != NULL, + ("proc_exec: emuldata not found.\n")); - EMUL_SHARED_WLOCK(&emul_shared_lock); - LIST_REMOVE(em, threads); + EMUL_SHARED_WLOCK(&emul_shared_lock); + LIST_REMOVE(em, threads); - PROC_LOCK(p); - p->p_emuldata = NULL; - PROC_UNLOCK(p); + PROC_LOCK(p); + p->p_emuldata = NULL; + PROC_UNLOCK(p); + + em->shared->refs--; + if (em->shared->refs == 0) { + EMUL_SHARED_WUNLOCK(&emul_shared_lock); + free(em->shared, M_LINUX); + } else + EMUL_SHARED_WUNLOCK(&emul_shared_lock); - em->shared->refs--; - if (em->shared->refs == 0) { - EMUL_SHARED_WUNLOCK(&emul_shared_lock); - free(em->shared, M_LINUX); - } else - EMUL_SHARED_WUNLOCK(&emul_shared_lock); + free(em, M_LINUX); + } - free(em, M_LINUX); + SDT_PROBE(LINUX_DTRACE, emul, proc_exec, return, 0, 0, 0, 0, 0); } } Modified: user/netchild/linuxulator-dtrace/src/sys/i386/linux/linux.h ============================================================================== --- user/netchild/linuxulator-dtrace/src/sys/i386/linux/linux.h Tue Nov 25 13:35:06 2008 (r185295) +++ user/netchild/linuxulator-dtrace/src/sys/i386/linux/linux.h Tue Nov 25 13:52:02 2008 (r185296) @@ -42,6 +42,7 @@ extern u_char linux_debug_map[]; #define ldebug(name) isclr(linux_debug_map, LINUX_SYS_linux_ ## name) #define ARGS(nm, fmt) "linux(%ld): "#nm"("fmt")\n", (long)td->td_proc->p_pid #define LMSG(fmt) "linux(%ld): "fmt"\n", (long)td->td_proc->p_pid +#define LINUX_DTRACE linuxulator #ifdef MALLOC_DECLARE MALLOC_DECLARE(M_LINUX); From owner-svn-src-user@FreeBSD.ORG Tue Nov 25 14:14:59 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 33E0C1065673; Tue, 25 Nov 2008 14:14:59 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 277558FC28; Tue, 25 Nov 2008 14:14:59 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mAPEEw3o025684; Tue, 25 Nov 2008 14:14:58 GMT (envelope-from netchild@svn.freebsd.org) Received: (from netchild@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mAPEEwRw025683; Tue, 25 Nov 2008 14:14:58 GMT (envelope-from netchild@svn.freebsd.org) Message-Id: <200811251414.mAPEEwRw025683@svn.freebsd.org> From: Alexander Leidinger Date: Tue, 25 Nov 2008 14:14:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185297 - user/netchild/linuxulator-dtrace/src/sys/compat/linux X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Nov 2008 14:14:59 -0000 Author: netchild Date: Tue Nov 25 14:14:58 2008 New Revision: 185297 URL: http://svn.freebsd.org/changeset/base/185297 Log: First dtrace program to check the balancing of the amul_lock aquire/release. As of now this will show errors, as not all locking/release places are instrumented with dtrace probes. WIP warning: This dtrace script is not even compile tested. Added: user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_emul_lock.d Added: user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_emul_lock.d ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_emul_lock.d Tue Nov 25 14:14:58 2008 (r185297) @@ -0,0 +1,36 @@ +#!/usr/sbin/dtrace -qs + +/* + * Check if the emul lock is correctly acquired/released: + * - no recursive locking + * - no unlocking of already unlocked one + */ + +linuxulator*::emul_locked +/check[probeprov, arg0] > 0/ +{ + printf("ERROR: recursive lock of emul_lock (%p),", arg0); + printf(" or missing SDT probe in kernel. Stack trace follows:"); + stack(); +} + +linuxulator*::emul_locked +{ + ++check[probeprov, arg0]; +} + +linuxulator*::emul_unlock +/check[probeprov, arg0] == 0/ +{ + printf("ERROR: unlock attemt of unlocked emul_lock (%p),", arg0); + printf(" missing SDT probe in kernel, or dtrace program started"); + printf(" while the emul_lock was already held (race condition)."); + printf(" Stack trace follows:"); + stack(); +} + +linuxulator*::emul_unlock +{ + --check[probeprov, arg0]; +} + From owner-svn-src-user@FreeBSD.ORG Thu Nov 27 10:28:26 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 96CCF106564A; Thu, 27 Nov 2008 10:28:26 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 877D58FC18; Thu, 27 Nov 2008 10:28:26 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mARASQmH084465; Thu, 27 Nov 2008 10:28:26 GMT (envelope-from netchild@svn.freebsd.org) Received: (from netchild@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mARASQNN084460; Thu, 27 Nov 2008 10:28:26 GMT (envelope-from netchild@svn.freebsd.org) Message-Id: <200811271028.mARASQNN084460@svn.freebsd.org> From: Alexander Leidinger Date: Thu, 27 Nov 2008 10:28:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185365 - user/netchild/linuxulator-dtrace/src/sys/compat/linux X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Nov 2008 10:28:26 -0000 Author: netchild Date: Thu Nov 27 10:28:26 2008 New Revision: 185365 URL: http://svn.freebsd.org/changeset/base/185365 Log: Finish dtrace probes in first linux file (module): - Fix bugs in previous commit. - Add more probes. - Add helper macros in separate header file to make the job of adding more probes a little bit more easy (and to make the bitsize dependand provider name actually work instead of using the macro name as the provider name). Add some more dtrace scripts, see comments in the scripts for their purpose. This is only compile tested so far. Added: user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_error.d (contents, props changed) user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_dtrace.h (contents, props changed) user/netchild/linuxulator-dtrace/src/sys/compat/linux/stats_timing.d (contents, props changed) Modified: user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_emul_lock.d (contents, props changed) user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_emul.c Modified: user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_emul_lock.d ============================================================================== --- user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_emul_lock.d Thu Nov 27 09:21:37 2008 (r185364) +++ user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_emul_lock.d Thu Nov 27 10:28:26 2008 (r185365) @@ -1,5 +1,35 @@ #!/usr/sbin/dtrace -qs +/*- + * Copyright (c) 2008 Alexander Leidinger + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + /* * Check if the emul lock is correctly acquired/released: * - no recursive locking Added: user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_error.d ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_error.d Thu Nov 27 10:28:26 2008 (r185365) @@ -0,0 +1,43 @@ +#!/usr/sbin/dtrace -qs + +/*- + * Copyright (c) 2008 Alexander Leidinger + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* Report error conditions. */ + +linuxulator*:emul:proc_exit:child_clear_tid_error, +linuxulator*:emul:proc_exit:futex_failed, +linuxulator*:emul:linux_schedtail:copyout_error +{ + printf("ERROR: %s in %s:%s:%s\n", probename, probeprov, probemod, probefunc); + stack(); + /* ustack(); */ /* needs to be enabled when PID tracing is available in FreeBSD dtrace */ +} + Added: user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_dtrace.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_dtrace.h Thu Nov 27 10:28:26 2008 (r185365) @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2008 Alexander Leidinger + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LINUX_DTRACE_H_ +#define _LINUX_DTRACE_H_ + +/* + * Some wrapper macros to make it more easy to handle the linuxulator + * providers and to allow to make the name depend upon the bitsize. + */ + +#define LIN_SDT_PROVIDER_DEFINE(x) SDT_PROVIDER_DEFINE(x) +#define LIN_SDT_PROVIDER_DECLARE(x) SDT_PROVIDER_DECLARE(x) + +#define _LIN_SDT_PROBE_DEFINE(a, b, c, d) SDT_PROBE_DEFINE(a, b, c, d) +#define LIN_SDT_PROBE_DEFINE(a, b, c) _LIN_SDT_PROBE_DEFINE(LINUX_DTRACE, a, \ + b, c) + +#define _LIN_SDT_PROBE_ARGTYPE(a, b, c, d, e, f) SDT_PROBE_ARGTYPE(a, b,\ + c, d, e, f) +#define LIN_SDT_PROBE_ARGTYPE(a, b, c, d, e) _LIN_SDT_PROBE_ARGTYPE( \ + LINUX_DTRACE, a, b, c, d, e) + +#define _LIN_SDT_PROBE(a, b, c, d, e, f, g, h, i) SDT_PROBE(a, b, c, d, \ + e, f, g, h, i) +#define LIN_SDT_PROBE(a, b, c, d, e, f, g, h) _LIN_SDT_PROBE(LINUX_DTRACE, \ + a, b, c, d, e, f, g, h) + +#endif /* _LINUX_DTRACE_H_ */ Modified: user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_emul.c ============================================================================== --- user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_emul.c Thu Nov 27 09:21:37 2008 (r185364) +++ user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_emul.c Thu Nov 27 10:28:26 2008 (r185365) @@ -60,55 +60,67 @@ __FBSDID("$FreeBSD$"); #include #include +#include /* * In this file we define the provider for the entire linuxulator. All * modules (= files of the linuxulator) use it. * * We define a different name depending on the emulated bitsize, see - * ../..//linux*/linux.h, e.g.: + * ../..//linux{,32}/linux.h, e.g.: * native bitsize = linuxulator * amd64, 32bit emulation = linuxulator32 */ -SDT_PROVIDER_DEFINE(LINUX_DTRACE); +LIN_SDT_PROVIDER_DEFINE(LINUX_DTRACE); /* DTrace probes in this module. */ -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, em_find, entry); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, em_find, entry, 0, "struct proc *"); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, em_find, entry, 1, "int"); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, em_find, emul_locked); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, em_find, emul_locked, 0, "struct mtx *"); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, em_find, emul_unlock); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, em_find, emul_unlock, 0, "struct mtx *"); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, em_find, return); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, em_find, return, 0, - "struct linux_emuldata *"); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_init, entry); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_init, entry, 0, "struct thread *"); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_init, entry, 1, "pid_t"); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_init, entry, 2, "int"); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_init, emul_unlock); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_init, emul_unlock, 0, +LIN_SDT_PROBE_DEFINE(emul, em_find, entry); +LIN_SDT_PROBE_ARGTYPE(emul, em_find, entry, 0, "struct proc *"); +LIN_SDT_PROBE_ARGTYPE(emul, em_find, entry, 1, "int"); +LIN_SDT_PROBE_DEFINE(emul, em_find, emul_locked); +LIN_SDT_PROBE_ARGTYPE(emul, em_find, emul_locked, 0, "struct mtx *"); +LIN_SDT_PROBE_DEFINE(emul, em_find, emul_unlock); +LIN_SDT_PROBE_ARGTYPE(emul, em_find, emul_unlock, 0, "struct mtx *"); +LIN_SDT_PROBE_DEFINE(emul, em_find, return); +LIN_SDT_PROBE_ARGTYPE(emul, em_find, return, 0, "struct linux_emuldata *"); +LIN_SDT_PROBE_DEFINE(emul, proc_init, entry); +LIN_SDT_PROBE_ARGTYPE(emul, proc_init, entry, 0, "struct thread *"); +LIN_SDT_PROBE_ARGTYPE(emul, proc_init, entry, 1, "pid_t"); +LIN_SDT_PROBE_ARGTYPE(emul, proc_init, entry, 2, "int"); +LIN_SDT_PROBE_DEFINE(emul, proc_init, create_thread); +LIN_SDT_PROBE_DEFINE(emul, proc_init, fork); +LIN_SDT_PROBE_DEFINE(emul, proc_init, exec); +LIN_SDT_PROBE_DEFINE(emul, proc_init, emul_unlock); +LIN_SDT_PROBE_ARGTYPE(emul, proc_init, emul_unlock, 0, "struct mtx *"); +LIN_SDT_PROBE_DEFINE(emul, proc_init, return); +LIN_SDT_PROBE_DEFINE(emul, proc_exit, entry); +LIN_SDT_PROBE_ARGTYPE(emul, proc_exit, entry, 0, "struct proc *"); +LIN_SDT_PROBE_DEFINE(emul, proc_exit, emul_unlock); +LIN_SDT_PROBE_ARGTYPE(emul, proc_exit, emul_unlock, 0, "struct mtx *"); +LIN_SDT_PROBE_DEFINE(emul, proc_exit, futex_failed); +LIN_SDT_PROBE_DEFINE(emul, proc_exit, reparent); +LIN_SDT_PROBE_ARGTYPE(emul, proc_exit, reparent, 0, "pid_t"); +LIN_SDT_PROBE_ARGTYPE(emul, proc_exit, reparent, 1, "pid_t"); +LIN_SDT_PROBE_ARGTYPE(emul, proc_exit, reparent, 2, "struct proc *"); +LIN_SDT_PROBE_DEFINE(emul, proc_exit, child_clear_tid_error); +LIN_SDT_PROBE_ARGTYPE(emul, proc_exit, child_clear_tid_error, 0, "int"); +LIN_SDT_PROBE_DEFINE(emul, proc_exit, return); +LIN_SDT_PROBE_DEFINE(emul, proc_exec, entry); +LIN_SDT_PROBE_ARGTYPE(emul, proc_exec, entry, 0, "struct proc *"); +LIN_SDT_PROBE_ARGTYPE(emul, proc_exec, entry, 1, "struct image_params *"); +LIN_SDT_PROBE_DEFINE(emul, proc_exec, return); +LIN_SDT_PROBE_DEFINE(emul, linux_schedtail, entry); +LIN_SDT_PROBE_DEFINE(emul, linux_schedtail, emul_unlock); +LIN_SDT_PROBE_ARGTYPE(emul, linux_schedtail, emul_unlock, 0, "struct mtx *"); +LIN_SDT_PROBE_DEFINE(emul, linux_schedtail, copyout_error); +LIN_SDT_PROBE_ARGTYPE(emul, linux_schedtail, copyout_error, 0, "int"); +LIN_SDT_PROBE_DEFINE(emul, linux_schedtail, return); +LIN_SDT_PROBE_DEFINE(emul, linux_set_tid_address, entry); +LIN_SDT_PROBE_ARGTYPE(emul, linux_set_tid_address, entry, 0, "int *"); +LIN_SDT_PROBE_DEFINE(emul, linux_set_tid_address, emul_unlock); +LIN_SDT_PROBE_ARGTYPE(emul, linux_set_tid_address, emul_unlock, 0, "struct mtx *"); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_init, return); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exit, entry); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exit, entry, 0, "struct proc *"); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exit, emul_unlock); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exit, emul_unlock, 0, - "struct mtx *"); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exit, reparent); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exit, reparent, 0, "pid_t"); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exit, reparent, 1, "pid_t"); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exit, reparent, 2, "struct proc *"); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exit, child_clear_tid_error); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exit, child_clear_tid_error, 0, - "int"); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exit, return); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exec, entry); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exec, entry, 0, "struct proc *"); -SDT_PROBE_ARGTYPE(LINUX_DTRACE, emul, proc_exec, entry, 0, - "struct image_params *"); -SDT_PROBE_DEFINE(LINUX_DTRACE, emul, proc_exec, return); +LIN_SDT_PROBE_DEFINE(emul, linux_set_tid_address, return); struct sx emul_shared_lock; struct mtx emul_lock; @@ -119,23 +131,23 @@ em_find(struct proc *p, int locked) { struct linux_emuldata *em; - SDT_PROBE(LINUX_DTRACE, emul, em_find, entry, p, locked, 0, 0, 0); + LIN_SDT_PROBE(emul, em_find, entry, p, locked, 0, 0, 0); if (locked == EMUL_DOLOCK) { EMUL_LOCK(&emul_lock); - SDT_PROBE(LINUX_DTRACE, emul, em_find, emul_lock, &emul_lock, + LIN_SDT_PROBE(emul, em_find, emul_locked, &emul_lock, 0, 0, 0, 0); } em = p->p_emuldata; if (em == NULL && locked == EMUL_DOLOCK) { - SDT_PROBE(LINUX_DTRACE, emul, em_find, emul_unlock, &emul_lock, + LIN_SDT_PROBE(emul, em_find, emul_unlock, &emul_lock, 0, 0, 0, 0); EMUL_UNLOCK(&emul_lock); } - SDT_PROBE(LINUX_DTRACE, emul, em_find, return, em, 0, 0, 0, 0); + LIN_SDT_PROBE(emul, em_find, return, em, 0, 0, 0, 0); return (em); } @@ -145,7 +157,7 @@ linux_proc_init(struct thread *td, pid_t struct linux_emuldata *em, *p_em; struct proc *p; - SDT_PROBE(LINUX_DTRACE, emul, proc_init, entry, td, child, flags, 0, 0); + LIN_SDT_PROBE(emul, proc_init, entry, td, child, flags, 0, 0); if (child != 0) { /* fork or create a thread */ @@ -156,12 +168,12 @@ linux_proc_init(struct thread *td, pid_t em->robust_futexes = NULL; if (flags & LINUX_CLONE_THREAD) { /* handled later in the code */ - SDT_PROBE(LINUX_DTRACE, emul, proc_init, create_thread, + LIN_SDT_PROBE(emul, proc_init, create_thread, 0, 0, 0, 0, 0); } else { struct linux_emuldata_shared *s; - SDT_PROBE(LINUX_DTRACE, emul, proc_init, fork, 0, 0, 0, + LIN_SDT_PROBE(emul, proc_init, fork, 0, 0, 0, 0, 0); s = malloc(sizeof *s, M_LINUX, M_WAITOK | M_ZERO); @@ -174,7 +186,7 @@ linux_proc_init(struct thread *td, pid_t } else { /* exec */ - SDT_PROBE(LINUX_DTRACE, emul, proc_init, exec, 0, 0, 0, 0, 0); + LIN_SDT_PROBE(emul, proc_init, exec, 0, 0, 0, 0, 0); /* lookup the old one */ em = em_find(td->td_proc, EMUL_DOLOCK); @@ -220,12 +232,12 @@ linux_proc_init(struct thread *td, pid_t p->p_emuldata = em; PROC_UNLOCK(p); } else { - SDT_PROBE(LINUX_DTRACE, emul, proc_init, emul_unlock, + LIN_SDT_PROBE(emul, proc_init, emul_unlock, &emul_lock, 0, 0, 0, 0); EMUL_UNLOCK(&emul_lock); } - SDT_PROBE(LINUX_DTRACE, emul, proc_init, return, 0, 0, 0, 0, 0); + LIN_SDT_PROBE(emul, proc_init, return, 0, 0, 0, 0, 0); return (0); } @@ -241,7 +253,7 @@ linux_proc_exit(void *arg __unused, stru if (__predict_true(p->p_sysent != &elf_linux_sysvec)) return; - SDT_PROBE(LINUX_DTRACE, emul, proc_exit, entry, p, 0, 0, 0, 0); + LIN_SDT_PROBE(emul, proc_exit, entry, p, 0, 0, 0, 0); release_futexes(p); @@ -251,12 +263,12 @@ linux_proc_exit(void *arg __unused, stru /* reparent all procs that are not a thread leader to initproc */ if (em->shared->group_pid != p->p_pid) { - SDT_PROBE(LINUX_DTRACE, emul, proc_exit, reparent, + LIN_SDT_PROBE(emul, proc_exit, reparent, em->shared->group_pid, p->p_pid, p, 0, 0); child_clear_tid = em->child_clear_tid; - SDT_PROBE(LINUX_DTRACE, emul, proc_exit, emul_unlock, + LIN_SDT_PROBE(emul, proc_exit, emul_unlock, &emul_lock, 0, 0, 0, 0); EMUL_UNLOCK(&emul_lock); @@ -270,7 +282,7 @@ linux_proc_exit(void *arg __unused, stru } else { child_clear_tid = em->child_clear_tid; - SDT_PROBE(LINUX_DTRACE, emul, proc_exit, emul_unlock, + LIN_SDT_PROBE(emul, proc_exit, emul_unlock, &emul_lock, 0, 0, 0, 0); EMUL_UNLOCK(&emul_lock); } @@ -291,12 +303,12 @@ linux_proc_exit(void *arg __unused, stru error = copyout(&null, child_clear_tid, sizeof(null)); if (error) { - SDT_PROBE(LINUX_DTRACE, emul, proc_exit, + LIN_SDT_PROBE(emul, proc_exit, child_clear_tid_error, error, 0, 0, 0, 0); free(em, M_LINUX); - SDT_PROBE(LINUX_DTRACE, emul, proc_exit, return, 0, 0, + LIN_SDT_PROBE(emul, proc_exit, return, 0, 0, 0, 0, 0); return; } @@ -314,7 +326,7 @@ linux_proc_exit(void *arg __unused, stru * probably means there is a user space bug */ if (error) { - SDT_PROBE(LINUX_DTRACE, emul, proc_exit, futex_failed, + LIN_SDT_PROBE(emul, proc_exit, futex_failed, 0, 0, 0, 0, 0); printf(LMSG("futex stuff in proc_exit failed.\n")); } @@ -339,13 +351,13 @@ linux_proc_exit(void *arg __unused, stru psignal(q, em->pdeath_signal); } PROC_UNLOCK(q); - SDT_PROBE(LINUX_DTRACE, emul, proc_exit, emul_unlock, + LIN_SDT_PROBE(emul, proc_exit, emul_unlock, &emul_lock, 0, 0, 0, 0); EMUL_UNLOCK(&emul_lock); } sx_xunlock(&proctree_lock); - SDT_PROBE(LINUX_DTRACE, emul, proc_exit, return, 0, 0, 0, 0, 0); + LIN_SDT_PROBE(emul, proc_exit, return, 0, 0, 0, 0, 0); } /* @@ -356,11 +368,11 @@ linux_proc_exit(void *arg __unused, stru void linux_proc_exec(void *arg __unused, struct proc *p, struct image_params *imgp) { - if (__predict_false(imgp->sysent == &elf_linux_sysvec) { - SDT_PROBE(LINUX_DTRACE, emul, proc_exec, entry, p, imgp, 0, 0, + if (__predict_false(imgp->sysent == &elf_linux_sysvec)) { + LIN_SDT_PROBE(emul, proc_exec, entry, p, imgp, 0, 0, 0); - if (p->p_sysent != &elf_linux_sysvec)) + if (p->p_sysent != &elf_linux_sysvec) linux_proc_init(FIRST_THREAD_IN_PROC(p), p->p_pid, 0); else { struct linux_emuldata *em; @@ -393,7 +405,7 @@ linux_proc_exec(void *arg __unused, stru free(em, M_LINUX); } - SDT_PROBE(LINUX_DTRACE, emul, proc_exec, return, 0, 0, 0, 0, 0); + LIN_SDT_PROBE(emul, proc_exec, return, 0, 0, 0, 0, 0); } } @@ -407,17 +419,30 @@ linux_schedtail(void *arg __unused, stru if (__predict_true(p->p_sysent != &elf_linux_sysvec)) return; + LIN_SDT_PROBE(emul, linux_schedtail, entry, p, 0, 0, 0, 0); + /* find the emuldata */ em = em_find(p, EMUL_DOLOCK); KASSERT(em != NULL, ("linux_schedtail: emuldata not found.\n")); child_set_tid = em->child_set_tid; + + LIN_SDT_PROBE(emul, linux_schedtail, emul_unlock, &emul_lock, + 0, 0, 0, 0); EMUL_UNLOCK(&emul_lock); - if (child_set_tid != NULL) + if (child_set_tid != NULL) { error = copyout(&p->p_pid, (int *)child_set_tid, sizeof(p->p_pid)); + if (error != 0) { + LIN_SDT_PROBE(emul, linux_schedtail, + copyout_error, error, 0, 0, 0, 0); + } + } + + LIN_SDT_PROBE(emul, linux_schedtail, return, 0, 0, 0, 0, 0); + return; } @@ -426,19 +451,21 @@ linux_set_tid_address(struct thread *td, { struct linux_emuldata *em; -#ifdef DEBUG - if (ldebug(set_tid_address)) - printf(ARGS(set_tid_address, "%p"), args->tidptr); -#endif + LIN_SDT_PROBE(emul, linux_set_tid_address, entry, + args->tidptr, 0, 0, 0, 0); /* find the emuldata */ em = em_find(td->td_proc, EMUL_DOLOCK); - KASSERT(em != NULL, ("set_tid_address: emuldata not found.\n")); em->child_clear_tid = args->tidptr; td->td_retval[0] = td->td_proc->p_pid; + LIN_SDT_PROBE(emul, linux_set_tid_address, emul_unlock, + &emul_lock, 0, 0, 0, 0); EMUL_UNLOCK(&emul_lock); + + LIN_SDT_PROBE(emul, linux_set_tid_address, return, 0, 0, 0, + 0, 0); return 0; } Added: user/netchild/linuxulator-dtrace/src/sys/compat/linux/stats_timing.d ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/netchild/linuxulator-dtrace/src/sys/compat/linux/stats_timing.d Thu Nov 27 10:28:26 2008 (r185365) @@ -0,0 +1,69 @@ +#!/usr/sbin/dtrace -qs + +/*- + * Copyright (c) 2008 Alexander Leidinger + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Some statistics (all per provider): + * - number of calls to a function per executable binary (not per PID!) + * - allows to see where an optimization would be beneficial for a given + * application + * - graph of CPU time spend in functions per executable binary + * - together with the number of calls to this function this allows + * to determine if a kernel optimization would be beneficial / is + * possible for a given application + * - graph of longest running (CPU-time!) function in total + * - may help finding problem cases in the kernel code + */ + +linuxulator*:::entry +{ + self->time[funcname] = vtimestamp; + @calls[probeprov, execname, probefunc] = count(); +} + +linuxulator*:::return +/self->time[funcname] != 0/ +{ + this->timediff = self->time[probefunc] - vtimestamp; + + @stats[probeprov, execname, probefunc] = quantize(this->timediff); + @longest[probeprov, probefunc] = max(this->timediff); + + self->time[probefunc] = 0; +} + +END +{ + printa("Number of calls per provider/application/kernel function", @calls); + printa("CPU-timing statistics per provider/application/kernel function (in ns)", @stats); + printa("Longest running (CPU-time!) functions per provider (in ns)", @longest); +} + From owner-svn-src-user@FreeBSD.ORG Thu Nov 27 10:58:17 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5598D1065674; Thu, 27 Nov 2008 10:58:17 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 453B58FC1F; Thu, 27 Nov 2008 10:58:17 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mARAwHho085149; Thu, 27 Nov 2008 10:58:17 GMT (envelope-from netchild@svn.freebsd.org) Received: (from netchild@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mARAwHb5085148; Thu, 27 Nov 2008 10:58:17 GMT (envelope-from netchild@svn.freebsd.org) Message-Id: <200811271058.mARAwHb5085148@svn.freebsd.org> From: Alexander Leidinger Date: Thu, 27 Nov 2008 10:58:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185367 - user/netchild/linuxulator-dtrace/src/sys/compat/linux X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Nov 2008 10:58:17 -0000 Author: netchild Date: Thu Nov 27 10:58:16 2008 New Revision: 185367 URL: http://svn.freebsd.org/changeset/base/185367 Log: Use the right built-in variable name. Modified: user/netchild/linuxulator-dtrace/src/sys/compat/linux/stats_timing.d Modified: user/netchild/linuxulator-dtrace/src/sys/compat/linux/stats_timing.d ============================================================================== --- user/netchild/linuxulator-dtrace/src/sys/compat/linux/stats_timing.d Thu Nov 27 10:43:08 2008 (r185366) +++ user/netchild/linuxulator-dtrace/src/sys/compat/linux/stats_timing.d Thu Nov 27 10:58:16 2008 (r185367) @@ -45,12 +45,12 @@ linuxulator*:::entry { - self->time[funcname] = vtimestamp; + self->time[probefunc] = vtimestamp; @calls[probeprov, execname, probefunc] = count(); } linuxulator*:::return -/self->time[funcname] != 0/ +/self->time[probefunc] != 0/ { this->timediff = self->time[probefunc] - vtimestamp; From owner-svn-src-user@FreeBSD.ORG Thu Nov 27 11:25:21 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ECA70106564A; Thu, 27 Nov 2008 11:25:21 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C09088FC18; Thu, 27 Nov 2008 11:25:21 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mARBPLo6085781; Thu, 27 Nov 2008 11:25:21 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mARBPLMg085780; Thu, 27 Nov 2008 11:25:21 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <200811271125.mARBPLMg085780@svn.freebsd.org> From: Edwin Groothuis Date: Thu, 27 Nov 2008 11:25:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185368 - in user/edwin/releasenotes/releng-7.1: . release X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Nov 2008 11:25:22 -0000 Author: edwin Date: Thu Nov 27 11:25:21 2008 New Revision: 185368 URL: http://svn.freebsd.org/changeset/base/185368 Log: Prepare for contributed software registration experiment - releng 7.1 Added: user/edwin/releasenotes/releng-7.1/ user/edwin/releasenotes/releng-7.1/release/ (props changed) - copied from r185367, releng/7.1/release/ From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 14:47:40 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 10C311065672; Fri, 28 Nov 2008 14:47:40 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0367A8FC0C; Fri, 28 Nov 2008 14:47:40 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASEldOb021599; Fri, 28 Nov 2008 14:47:39 GMT (envelope-from netchild@svn.freebsd.org) Received: (from netchild@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASEldl0021598; Fri, 28 Nov 2008 14:47:39 GMT (envelope-from netchild@svn.freebsd.org) Message-Id: <200811281447.mASEldl0021598@svn.freebsd.org> From: Alexander Leidinger Date: Fri, 28 Nov 2008 14:47:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185383 - user/netchild/linuxulator-dtrace/src/sys/compat/linux X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 14:47:40 -0000 Author: netchild Date: Fri Nov 28 14:47:39 2008 New Revision: 185383 URL: http://svn.freebsd.org/changeset/base/185383 Log: Those includes are not needed for dtrace. Modified: user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_emul.c Modified: user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_emul.c ============================================================================== --- user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_emul.c Fri Nov 28 13:13:44 2008 (r185382) +++ user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_emul.c Fri Nov 28 14:47:39 2008 (r185383) @@ -31,7 +31,6 @@ __FBSDID("$FreeBSD$"); #include "opt_compat.h" #include "opt_kdtrace.h" -#include "opt_ktrace.h" #include #include @@ -46,9 +45,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#ifdef KTRACE -#include -#endif #ifdef COMPAT_LINUX32 #include From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 14:49:26 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B692C1065676; Fri, 28 Nov 2008 14:49:26 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A75FC8FC1A; Fri, 28 Nov 2008 14:49:26 +0000 (UTC) (envelope-from netchild@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASEnQVo021672; Fri, 28 Nov 2008 14:49:26 GMT (envelope-from netchild@svn.freebsd.org) Received: (from netchild@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASEnQI3021670; Fri, 28 Nov 2008 14:49:26 GMT (envelope-from netchild@svn.freebsd.org) Message-Id: <200811281449.mASEnQI3021670@svn.freebsd.org> From: Alexander Leidinger Date: Fri, 28 Nov 2008 14:49:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185384 - user/netchild/linuxulator-dtrace/src/sys/compat/linux X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 14:49:26 -0000 Author: netchild Date: Fri Nov 28 14:49:26 2008 New Revision: 185384 URL: http://svn.freebsd.org/changeset/base/185384 Log: Add dtrace probes to all functions in linux_util.c. This is only compiletested. Add some error probes from linux_util to the error checking dtrace script. Modified: user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_error.d user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_util.c Modified: user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_error.d ============================================================================== --- user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_error.d Fri Nov 28 14:47:39 2008 (r185383) +++ user/netchild/linuxulator-dtrace/src/sys/compat/linux/check_error.d Fri Nov 28 14:49:26 2008 (r185384) @@ -41,3 +41,18 @@ linuxulator*:emul:linux_schedtail:copyou /* ustack(); */ /* needs to be enabled when PID tracing is available in FreeBSD dtrace */ } +linuxulator*:util:linux_driver_get_name_dev:nullcall, +linuxulator*:util:linux_driver_get_major_minor:nullcall +{ + printf("WARNING: %s:%s:%s:%s in application %s, maybe an application error?\n", probename, probeprov, probemod, probefunc, execname); + stack(); + /* ustack(); */ /* needs to be enabled when PID tracing is available in FreeBSD dtrace */ +} + +linuxulator*:util:linux_driver_get_major_minor:notfound +{ + printf("WARNING: Application %s failed to find %s in %s:%s:%s, this may or may not be a problem.\n", execname, arg0, probename, probeprov, probemod); + stack(); + /* ustack(); */ /* needs to be enabled when PID tracing is available in FreeBSD dtrace */ +} + Modified: user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_util.c ============================================================================== --- user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_util.c Fri Nov 28 14:47:39 2008 (r185383) +++ user/netchild/linuxulator-dtrace/src/sys/compat/linux/linux_util.c Fri Nov 28 14:49:26 2008 (r185384) @@ -33,16 +33,19 @@ __FBSDID("$FreeBSD$"); #include "opt_compat.h" +#include "opt_kdtrace.h" #include #include #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -56,8 +59,58 @@ __FBSDID("$FreeBSD$"); #include #endif +#include + const char linux_emul_path[] = "/compat/linux"; +LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE); +LIN_SDT_PROBE_DEFINE(util, linux_emul_convpath, entry); +LIN_SDT_PROBE_ARGTYPE(util, linux_emul_convpath, entry, 0, "const char *"); +LIN_SDT_PROBE_ARGTYPE(util, linux_emul_convpath, entry, 1, "enum uio_seg"); +LIN_SDT_PROBE_ARGTYPE(util, linux_emul_convpath, entry, 2, "char **"); +LIN_SDT_PROBE_ARGTYPE(util, linux_emul_convpath, entry, 3, "int"); +LIN_SDT_PROBE_ARGTYPE(util, linux_emul_convpath, entry, 4, "int"); +LIN_SDT_PROBE_DEFINE(util, linux_emul_convpath, return); +LIN_SDT_PROBE_ARGTYPE(util, linux_emul_convpath, return, 0, "int"); +LIN_SDT_PROBE_DEFINE(util, linux_msg, entry); +LIN_SDT_PROBE_ARGTYPE(util, linux_msg, entry, 0, "const char *"); +LIN_SDT_PROBE_DEFINE(util, linux_msg, return); +LIN_SDT_PROBE_DEFINE(util, linux_driver_get_name_dev, entry); +LIN_SDT_PROBE_ARGTYPE(util, linux_driver_get_name_dev, entry, 0, "device_t"); +LIN_SDT_PROBE_ARGTYPE(util, linux_driver_get_name_dev, entry, 1, + "const char *"); +LIN_SDT_PROBE_DEFINE(util, linux_driver_get_name_dev, nullcall); +LIN_SDT_PROBE_DEFINE(util, linux_driver_get_name_dev, return); +LIN_SDT_PROBE_ARGTYPE(util, linux_driver_get_name_dev, return, 0, "char *"); +LIN_SDT_PROBE_DEFINE(util, linux_driver_get_major_minor, entry); +LIN_SDT_PROBE_ARGTYPE(util, linux_driver_get_major_minor, entry, 0, "char *"); +LIN_SDT_PROBE_ARGTYPE(util, linux_driver_get_major_minor, entry, 1, "int *"); +LIN_SDT_PROBE_ARGTYPE(util, linux_driver_get_major_minor, entry, 2, "int *"); +LIN_SDT_PROBE_DEFINE(util, linux_driver_get_major_minor, nullcall); +LIN_SDT_PROBE_DEFINE(util, linux_driver_get_major_minor, notfound); +LIN_SDT_PROBE_ARGTYPE(util, linux_driver_get_major_minor, notfound, 0, + "char *"); +LIN_SDT_PROBE_DEFINE(util, linux_driver_get_major_minor, return); +LIN_SDT_PROBE_ARGTYPE(util, linux_driver_get_major_minor, return, 0, "int"); +LIN_SDT_PROBE_ARGTYPE(util, linux_driver_get_major_minor, return, 1, "int"); +LIN_SDT_PROBE_ARGTYPE(util, linux_driver_get_major_minor, return, 2, "int"); +LIN_SDT_PROBE_DEFINE(util, linux_get_char_devices, entry); +LIN_SDT_PROBE_DEFINE(util, linux_get_char_devices, return); +LIN_SDT_PROBE_ARGTYPE(util, linux_get_char_devices, return, 0, "char *"); +LIN_SDT_PROBE_DEFINE(util, linux_free_get_char_devices, entry); +LIN_SDT_PROBE_ARGTYPE(util, linux_free_get_char_devices, entry, 0, "char *"); +LIN_SDT_PROBE_DEFINE(util, linux_free_get_char_devices, return); +LIN_SDT_PROBE_DEFINE(util, linux_device_register_handler, entry); +LIN_SDT_PROBE_ARGTYPE(util, linux_device_register_handler, entry, 0, + "struct linux_device_handler *"); +LIN_SDT_PROBE_DEFINE(util, linux_device_register_handler, return); +LIN_SDT_PROBE_ARGTYPE(util, linux_device_register_handler, return, 0, "int"); +LIN_SDT_PROBE_DEFINE(util, linux_device_unregister_handler, entry); +LIN_SDT_PROBE_ARGTYPE(util, linux_device_unregister_handler, entry, 0, + "struct linux_device_handler *"); +LIN_SDT_PROBE_DEFINE(util, linux_device_unregister_handler, return); +LIN_SDT_PROBE_ARGTYPE(util, linux_device_unregister_handler, return, 0, "int"); + /* * Search an alternate path before passing pathname arguments on to * system calls. Useful for keeping a separate 'emulation tree'. @@ -66,17 +119,20 @@ const char linux_emul_path[] = "/co * named file, i.e. we check if the directory it should be in exists. */ int -linux_emul_convpath(td, path, pathseg, pbuf, cflag, dfd) - struct thread *td; - const char *path; - enum uio_seg pathseg; - char **pbuf; - int cflag; - int dfd; +linux_emul_convpath(struct thread *td, const char *path, enum uio_seg pathseg, + char **pbuf, int cflag, int dfd) { + int retval; + + LIN_SDT_PROBE(util, linux_emul_convpath, entry, path, pathseg, pbuf, + cflag, dfd); - return (kern_alternate_path(td, linux_emul_path, path, pathseg, pbuf, - cflag, dfd)); + retval = kern_alternate_path(td, linux_emul_path, path, pathseg, pbuf, + cflag, dfd); + + LIN_SDT_PROBE(util, linux_emul_convpath, return, retval, 0, 0, 0, 0); + + return (retval); } void @@ -85,12 +141,16 @@ linux_msg(const struct thread *td, const va_list ap; struct proc *p; + LIN_SDT_PROBE(util, linux_msg, entry, fmt, 0, 0, 0, 0); + p = td->td_proc; printf("linux: pid %d (%s): ", (int)p->p_pid, p->p_comm); va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); printf("\n"); + + LIN_SDT_PROBE(util, linux_msg, return, 0, 0, 0, 0, 0); } struct device_element @@ -113,13 +173,26 @@ linux_driver_get_name_dev(device_t dev) struct device_element *de; const char *device_name = device_get_name(dev); - if (device_name == NULL) + LIN_SDT_PROBE(util, linux_driver_get_name_dev, entry, dev, + device_name, 0, 0, 0); + + if (device_name == NULL) { + LIN_SDT_PROBE(util, linux_driver_get_name_dev, nullcall, 0, 0, + 0, 0, 0); + LIN_SDT_PROBE(util, linux_driver_get_name_dev, return, NULL, + 0, 0, 0, 0); return NULL; + } TAILQ_FOREACH(de, &devices, list) { - if (strcmp(device_name, de->entry.bsd_driver_name) == 0) + if (strcmp(device_name, de->entry.bsd_driver_name) == 0) { + LIN_SDT_PROBE(util, linux_driver_get_name_dev, return, + de->entry.linux_driver_name, 0, 0, 0, 0); return (de->entry.linux_driver_name); + } } + LIN_SDT_PROBE(util, linux_driver_get_name_dev, return, NULL, 0, 0, 0, + 0); return NULL; } @@ -128,8 +201,16 @@ linux_driver_get_major_minor(char *node, { struct device_element *de; - if (node == NULL || major == NULL || minor == NULL) + LIN_SDT_PROBE(util, linux_driver_get_major_minor, entry, node, major, + minor, 0, 0); + + if (node == NULL || major == NULL || minor == NULL) { + LIN_SDT_PROBE(util, linux_driver_get_major_minor, nullcall, 0, + 0, 0, 0, 0); + LIN_SDT_PROBE(util, linux_driver_get_major_minor, return, 1, + *major, *minor, 0, 0); return 1; + } if (strlen(node) > strlen("pts/") && strncmp(node, "pts/", strlen("pts/")) == 0) { @@ -143,6 +224,9 @@ linux_driver_get_major_minor(char *node, devno = strtoul(node + strlen("pts/"), NULL, 10); *major = 136 + (devno / 256); *minor = devno % 256; + + LIN_SDT_PROBE(util, linux_driver_get_major_minor, return, 0, + *major, *minor, 0, 0); return 0; } @@ -150,21 +234,30 @@ linux_driver_get_major_minor(char *node, if (strcmp(node, de->entry.bsd_device_name) == 0) { *major = de->entry.linux_major; *minor = de->entry.linux_minor; + + LIN_SDT_PROBE(util, linux_driver_get_major_minor, + return, 0, *major, *minor, 0, 0); return 0; } } + LIN_SDT_PROBE(util, linux_driver_get_major_minor, notfound, node, 0, 0, + 0, 0); + LIN_SDT_PROBE(util, linux_driver_get_major_minor, return, 1, *major, + *minor, 0, 0); return 1; } char * -linux_get_char_devices() +linux_get_char_devices(void) { struct device_element *de; char *temp, *string, *last; char formated[256]; int current_size = 0, string_size = 1024; + LIN_SDT_PROBE(util, linux_get_char_devices, entry, 0, 0, 0, 0, 0); + string = malloc(string_size, M_LINUX, M_WAITOK); string[0] = '\000'; last = ""; @@ -191,13 +284,19 @@ linux_get_char_devices() } } + LIN_SDT_PROBE(util, linux_get_char_devices, return, string, 0, 0, 0, 0); return string; } void linux_free_get_char_devices(char *string) { + + LIN_SDT_PROBE(util, linux_get_char_devices, entry, string, 0, 0, 0, 0); + free(string, M_LINUX); + + LIN_SDT_PROBE(util, linux_get_char_devices, return, 0, 0, 0, 0, 0); } static int linux_major_starting = 200; @@ -207,11 +306,16 @@ linux_device_register_handler(struct lin { struct device_element *de; - if (d == NULL) + LIN_SDT_PROBE(util, linux_device_register_handler, entry, d, 0, 0, 0, + 0); + + if (d == NULL) { + LIN_SDT_PROBE(util, linux_device_register_handler, return, + EINVAL, 0, 0, 0, 0); return (EINVAL); + } - de = malloc(sizeof(*de), - M_LINUX, M_WAITOK); + de = malloc(sizeof(*de), M_LINUX, M_WAITOK); if (d->linux_major < 0) { d->linux_major = linux_major_starting++; } @@ -220,6 +324,8 @@ linux_device_register_handler(struct lin /* Add the element to the list, sorted on span. */ TAILQ_INSERT_TAIL(&devices, de, list); + LIN_SDT_PROBE(util, linux_device_register_handler, return, 0, 0, 0, 0, + 0); return (0); } @@ -228,16 +334,27 @@ linux_device_unregister_handler(struct l { struct device_element *de; - if (d == NULL) + LIN_SDT_PROBE(util, linux_device_unregister_handler, entry, d, 0, 0, 0, + 0); + + if (d == NULL) { + LIN_SDT_PROBE(util, linux_device_unregister_handler, return, + EINVAL, 0, 0, 0, 0); return (EINVAL); + } TAILQ_FOREACH(de, &devices, list) { if (bcmp(d, &de->entry, sizeof(*d)) == 0) { TAILQ_REMOVE(&devices, de, list); free(de, M_LINUX); + + LIN_SDT_PROBE(util, linux_device_unregister_handler, + return, 0, 0, 0, 0, 0); return (0); } } + LIN_SDT_PROBE(util, linux_device_unregister_handler, return, EINVAL, 0, + 0, 0, 0); return (EINVAL); } From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 15:11:58 2008 Return-Path: Delivered-To: svn-src-user@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4E6341065674 for ; Fri, 28 Nov 2008 15:11:58 +0000 (UTC) (envelope-from rdivacky@lev.vlakno.cz) Received: from vlakno.cz (77-93-215-190.static.masterinter.net [77.93.215.190]) by mx1.freebsd.org (Postfix) with ESMTP id 0D6598FC0A for ; Fri, 28 Nov 2008 15:11:58 +0000 (UTC) (envelope-from rdivacky@lev.vlakno.cz) Received: from localhost (localhost [127.0.0.1]) by vlakno.cz (Postfix) with ESMTP id 6B7DF9CB24E; Fri, 28 Nov 2008 15:49:23 +0100 (CET) X-Virus-Scanned: amavisd-new at vlakno.cz Received: from vlakno.cz ([127.0.0.1]) by localhost (lev.vlakno.cz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VuL45jqLw-kQ; Fri, 28 Nov 2008 15:49:11 +0100 (CET) Received: from lev.vlakno.cz (localhost [127.0.0.1]) by vlakno.cz (Postfix) with ESMTP id D6C059CB298; Fri, 28 Nov 2008 15:49:11 +0100 (CET) Received: (from rdivacky@localhost) by lev.vlakno.cz (8.14.2/8.14.2/Submit) id mASEnBLG035842; Fri, 28 Nov 2008 15:49:11 +0100 (CET) (envelope-from rdivacky) Date: Fri, 28 Nov 2008 15:49:11 +0100 From: Roman Divacky To: Alexander Leidinger Message-ID: <20081128144911.GA35621@freebsd.org> References: <200811251414.mAPEEwRw025683@svn.freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200811251414.mAPEEwRw025683@svn.freebsd.org> User-Agent: Mutt/1.4.2.3i Cc: src-committers@FreeBSD.org, svn-src-user@FreeBSD.org Subject: Re: svn commit: r185297 - user/netchild/linuxulator-dtrace/src/sys/compat/linux X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 15:11:58 -0000 On Tue, Nov 25, 2008 at 02:14:58PM +0000, Alexander Leidinger wrote: > Author: netchild > Date: Tue Nov 25 14:14:58 2008 > New Revision: 185297 > URL: http://svn.freebsd.org/changeset/base/185297 > > Log: > First dtrace program to check the balancing of the amul_lock aquire/release. > > As of now this will show errors, as not all locking/release places are > instrumented with dtrace probes. > > WIP warning: This dtrace script is not even compile tested. what is the point of this? isnt this already handled by the lock primitive itself? ie. when you try to acquire mutex twice it panics, when you unlock not locked mutex it panics.... roman From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 15:49:37 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1A5D71065672; Fri, 28 Nov 2008 15:49:37 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0C9388FC17; Fri, 28 Nov 2008 15:49:37 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASFna9W022832; Fri, 28 Nov 2008 15:49:36 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASFnapa022825; Fri, 28 Nov 2008 15:49:36 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281549.mASFnapa022825@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 15:49:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185386 - in user/dfr/xenhvm/6/sys/amd64/include: . xen X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 15:49:37 -0000 Author: dfr Date: Fri Nov 28 15:49:36 2008 New Revision: 185386 URL: http://svn.freebsd.org/changeset/base/185386 Log: Add some Xen support for amd64 - initially HVM only. Added: user/dfr/xenhvm/6/sys/amd64/include/xen/ (props changed) - copied from r185181, user/dfr/xenhvm/6/sys/i386/include/xen/ Modified: user/dfr/xenhvm/6/sys/amd64/include/pcpu.h user/dfr/xenhvm/6/sys/amd64/include/xen/hypercall.h user/dfr/xenhvm/6/sys/amd64/include/xen/hypervisor.h user/dfr/xenhvm/6/sys/amd64/include/xen/synch_bitops.h user/dfr/xenhvm/6/sys/amd64/include/xen/xen-os.h user/dfr/xenhvm/6/sys/amd64/include/xen/xenfunc.h user/dfr/xenhvm/6/sys/amd64/include/xen/xenvar.h Modified: user/dfr/xenhvm/6/sys/amd64/include/pcpu.h ============================================================================== --- user/dfr/xenhvm/6/sys/amd64/include/pcpu.h Fri Nov 28 14:53:18 2008 (r185385) +++ user/dfr/xenhvm/6/sys/amd64/include/pcpu.h Fri Nov 28 15:49:36 2008 (r185386) @@ -35,6 +35,24 @@ #ifdef _KERNEL +#if defined(XEN) || defined(XENHVM) +#ifndef NR_VIRQS +#define NR_VIRQS 24 +#endif +#ifndef NR_IPIS +#define NR_IPIS 2 +#endif +#endif + +#ifdef XENHVM +#define PCPU_XEN_FIELDS \ + ; \ + unsigned int pc_last_processed_l1i; \ + unsigned int pc_last_processed_l2i +#else +#define PCPU_XEN_FIELDS +#endif + /* * The SMP parts are setup in pmap.c and locore.s for the BSP, and * mp_machdep.c sets up the data for the AP's to "see" when they awake. @@ -49,7 +67,8 @@ register_t pc_rsp0; \ register_t pc_scratch_rsp; /* User %rsp in syscall */ \ u_int pc_apic_id; \ - u_int pc_acpi_id /* ACPI CPU id */ + u_int pc_acpi_id /* ACPI CPU id */ \ + PCPU_XEN_FIELDS #if defined(lint) Modified: user/dfr/xenhvm/6/sys/amd64/include/xen/hypercall.h ============================================================================== --- user/dfr/xenhvm/6/sys/i386/include/xen/hypercall.h Sat Nov 22 16:14:52 2008 (r185181) +++ user/dfr/xenhvm/6/sys/amd64/include/xen/hypercall.h Fri Nov 28 15:49:36 2008 (r185386) @@ -5,8 +5,15 @@ * * Copyright (c) 2002-2004, K A Fraser * - * This file may be distributed separately from the Linux kernel, or - * incorporated into other software packages, subject to the following license: + * 64-bit updates: + * Benjamin Liu + * Jun Nakajima + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation; or, when distributed + * separately from the Linux kernel or incorporated into other + * software packages, subject to the following license: * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this source file (the "Software"), to deal in the Software without @@ -31,141 +38,151 @@ #define __HYPERCALL_H__ #include -#include -#include + +#ifndef __HYPERVISOR_H__ +# error "please don't include this file directly" +#endif #define __STR(x) #x #define STR(x) __STR(x) #define ENOXENSYS 38 #define CONFIG_XEN_COMPAT 0x030002 +#define __must_check - -#if defined(XEN) -#define HYPERCALL_STR(name) \ - "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)" +#ifdef XEN +#define HYPERCALL_STR(name) \ + "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)" #else -#define HYPERCALL_STR(name) \ - "mov hypercall_stubs,%%eax; " \ - "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; " \ - "call *%%eax" +#define HYPERCALL_STR(name) \ + "mov $("STR(__HYPERVISOR_##name)" * 32),%%eax; "\ + "add hypercall_stubs(%%rip),%%rax; " \ + "call *%%rax" #endif -#define _hypercall0(type, name) \ -({ \ - long __res; \ - __asm__ volatile ( \ - HYPERCALL_STR(name) \ - : "=a" (__res) \ - : \ - : "memory" ); \ - (type)__res; \ +#define _hypercall0(type, name) \ +({ \ + type __res; \ + __asm__ volatile ( \ + HYPERCALL_STR(name) \ + : "=a" (__res) \ + : \ + : "memory" ); \ + __res; \ }) -#define _hypercall1(type, name, a1) \ -({ \ - long __res, __ign1; \ - __asm__ volatile ( \ - HYPERCALL_STR(name) \ - : "=a" (__res), "=b" (__ign1) \ - : "1" ((long)(a1)) \ - : "memory" ); \ - (type)__res; \ +#define _hypercall1(type, name, a1) \ +({ \ + type __res; \ + long __ign1; \ + __asm__ volatile ( \ + HYPERCALL_STR(name) \ + : "=a" (__res), "=D" (__ign1) \ + : "1" ((long)(a1)) \ + : "memory" ); \ + __res; \ }) -#define _hypercall2(type, name, a1, a2) \ -({ \ - long __res, __ign1, __ign2; \ - __asm__ volatile ( \ - HYPERCALL_STR(name) \ - : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \ - : "1" ((long)(a1)), "2" ((long)(a2)) \ - : "memory" ); \ - (type)__res; \ +#define _hypercall2(type, name, a1, a2) \ +({ \ + type __res; \ + long __ign1, __ign2; \ + __asm__ volatile ( \ + HYPERCALL_STR(name) \ + : "=a" (__res), "=D" (__ign1), "=S" (__ign2) \ + : "1" ((long)(a1)), "2" ((long)(a2)) \ + : "memory" ); \ + __res; \ }) -#define _hypercall3(type, name, a1, a2, a3) \ -({ \ - long __res, __ign1, __ign2, __ign3; \ - __asm__ volatile ( \ - HYPERCALL_STR(name) \ - : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ - "=d" (__ign3) \ - : "1" ((long)(a1)), "2" ((long)(a2)), \ - "3" ((long)(a3)) \ - : "memory" ); \ - (type)__res; \ +#define _hypercall3(type, name, a1, a2, a3) \ +({ \ + type __res; \ + long __ign1, __ign2, __ign3; \ + __asm__ volatile ( \ + HYPERCALL_STR(name) \ + : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \ + "=d" (__ign3) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)) \ + : "memory" ); \ + __res; \ }) -#define _hypercall4(type, name, a1, a2, a3, a4) \ -({ \ - long __res, __ign1, __ign2, __ign3, __ign4; \ - __asm__ volatile ( \ - HYPERCALL_STR(name) \ - : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ - "=d" (__ign3), "=S" (__ign4) \ - : "1" ((long)(a1)), "2" ((long)(a2)), \ - "3" ((long)(a3)), "4" ((long)(a4)) \ - : "memory" ); \ - (type)__res; \ +#define _hypercall4(type, name, a1, a2, a3, a4) \ +({ \ + type __res; \ + long __ign1, __ign2, __ign3; \ + register long __arg4 __asm__("r10") = (long)(a4); \ + __asm__ volatile ( \ + HYPERCALL_STR(name) \ + : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \ + "=d" (__ign3), "+r" (__arg4) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)) \ + : "memory" ); \ + __res; \ }) -#define _hypercall5(type, name, a1, a2, a3, a4, a5) \ -({ \ - long __res, __ign1, __ign2, __ign3, __ign4, __ign5; \ - __asm__ volatile ( \ - HYPERCALL_STR(name) \ - : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ - "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) \ - : "1" ((long)(a1)), "2" ((long)(a2)), \ - "3" ((long)(a3)), "4" ((long)(a4)), \ - "5" ((long)(a5)) \ - : "memory" ); \ - (type)__res; \ -}) +#define _hypercall5(type, name, a1, a2, a3, a4, a5) \ +({ \ + type __res; \ + long __ign1, __ign2, __ign3; \ + register long __arg4 __asm__("r10") = (long)(a4); \ + register long __arg5 __asm__("r8") = (long)(a5); \ + __asm__ volatile ( \ + HYPERCALL_STR(name) \ + : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \ + "=d" (__ign3), "+r" (__arg4), "+r" (__arg5) \ + : "1" ((long)(a1)), "2" ((long)(a2)), \ + "3" ((long)(a3)) \ + : "memory" ); \ + __res; \ +}) -static inline int +static inline int __must_check HYPERVISOR_set_trap_table( - trap_info_t *table) + const trap_info_t *table) { return _hypercall1(int, set_trap_table, table); } -static inline int +static inline int __must_check HYPERVISOR_mmu_update( - mmu_update_t *req, int count, int *success_count, domid_t domid) + mmu_update_t *req, unsigned int count, unsigned int *success_count, + domid_t domid) { return _hypercall4(int, mmu_update, req, count, success_count, domid); } -static inline int +static inline int __must_check HYPERVISOR_mmuext_op( - mmuext_op_t *op, int count, int *success_count, domid_t domid) + struct mmuext_op *op, unsigned int count, unsigned int *success_count, + domid_t domid) { return _hypercall4(int, mmuext_op, op, count, success_count, domid); } -static inline int +static inline int __must_check HYPERVISOR_set_gdt( - unsigned long *frame_list, int entries) + unsigned long *frame_list, unsigned int entries) { return _hypercall2(int, set_gdt, frame_list, entries); } -static inline int +static inline int __must_check HYPERVISOR_stack_switch( unsigned long ss, unsigned long esp) { return _hypercall2(int, stack_switch, ss, esp); } -static inline int +static inline int __must_check HYPERVISOR_set_callbacks( - unsigned long event_selector, unsigned long event_address, - unsigned long failsafe_selector, unsigned long failsafe_address) + unsigned long event_address, unsigned long failsafe_address, + unsigned long syscall_address) { - return _hypercall4(int, set_callbacks, - event_selector, event_address, - failsafe_selector, failsafe_address); + return _hypercall3(int, set_callbacks, + event_address, failsafe_address, syscall_address); } static inline int @@ -175,93 +192,85 @@ HYPERVISOR_fpu_taskswitch( return _hypercall1(int, fpu_taskswitch, set); } -static inline int +static inline int __must_check HYPERVISOR_sched_op_compat( int cmd, unsigned long arg) { return _hypercall2(int, sched_op_compat, cmd, arg); } -static inline int +static inline int __must_check HYPERVISOR_sched_op( int cmd, void *arg) { return _hypercall2(int, sched_op, cmd, arg); } -static inline long +static inline long __must_check HYPERVISOR_set_timer_op( uint64_t timeout) { - unsigned long timeout_hi = (unsigned long)(timeout>>32); - unsigned long timeout_lo = (unsigned long)timeout; - return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi); + return _hypercall1(long, set_timer_op, timeout); } -#if 0 -static inline int + +static inline int __must_check HYPERVISOR_platform_op( - struct xen_platform_op *platform_op) + struct xen_platform_op *platform_op) { - platform_op->interface_version = XENPF_INTERFACE_VERSION; - return _hypercall1(int, platform_op, platform_op); + platform_op->interface_version = XENPF_INTERFACE_VERSION; + return _hypercall1(int, platform_op, platform_op); } -#endif -static inline int + +static inline int __must_check HYPERVISOR_set_debugreg( - int reg, unsigned long value) + unsigned int reg, unsigned long value) { return _hypercall2(int, set_debugreg, reg, value); } -static inline unsigned long +static inline unsigned long __must_check HYPERVISOR_get_debugreg( - int reg) + unsigned int reg) { return _hypercall1(unsigned long, get_debugreg, reg); } -static inline int +static inline int __must_check HYPERVISOR_update_descriptor( - uint64_t ma, uint64_t desc) + unsigned long ma, unsigned long word) { - return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32); + return _hypercall2(int, update_descriptor, ma, word); } -static inline int +static inline int __must_check HYPERVISOR_memory_op( unsigned int cmd, void *arg) { return _hypercall2(int, memory_op, cmd, arg); } -static inline int +static inline int __must_check HYPERVISOR_multicall( - void *call_list, int nr_calls) + multicall_entry_t *call_list, unsigned int nr_calls) { return _hypercall2(int, multicall, call_list, nr_calls); } -static inline int +static inline int __must_check HYPERVISOR_update_va_mapping( unsigned long va, uint64_t new_val, unsigned long flags) { - uint32_t hi, lo; - - lo = (uint32_t)(new_val & 0xffffffff); - hi = (uint32_t)(new_val >> 32); - - return _hypercall4(int, update_va_mapping, va, - lo, hi, flags); + return _hypercall3(int, update_va_mapping, va, new_val, flags); } -static inline int +static inline int __must_check HYPERVISOR_event_channel_op( int cmd, void *arg) { int rc = _hypercall2(int, event_channel_op, cmd, arg); #if CONFIG_XEN_COMPAT <= 0x030002 - if (__predict_false(rc == -ENOXENSYS)) { + if (unlikely(rc == -ENOXENSYS)) { struct evtchn_op op; op.cmd = cmd; memcpy(&op.u, arg, sizeof(op.u)); @@ -269,30 +278,32 @@ HYPERVISOR_event_channel_op( memcpy(arg, &op.u, sizeof(op.u)); } #endif - return (rc); + + return rc; } -static inline int +static inline int __must_check HYPERVISOR_xen_version( int cmd, void *arg) { return _hypercall2(int, xen_version, cmd, arg); } -static inline int +static inline int __must_check HYPERVISOR_console_io( - int cmd, int count, char *str) + int cmd, unsigned int count, char *str) { return _hypercall3(int, console_io, cmd, count, str); } -static inline int +static inline int __must_check HYPERVISOR_physdev_op( int cmd, void *arg) { int rc = _hypercall2(int, physdev_op, cmd, arg); + #if CONFIG_XEN_COMPAT <= 0x030002 - if (__predict_false(rc == -ENOXENSYS)) { + if (unlikely(rc == -ENOXENSYS)) { struct physdev_op op; op.cmd = cmd; memcpy(&op.u, arg, sizeof(op.u)); @@ -300,78 +311,77 @@ HYPERVISOR_physdev_op( memcpy(arg, &op.u, sizeof(op.u)); } #endif - return (rc); + + return rc; } -static inline int +static inline int __must_check HYPERVISOR_grant_table_op( unsigned int cmd, void *uop, unsigned int count) { return _hypercall3(int, grant_table_op, cmd, uop, count); } -static inline int +static inline int __must_check HYPERVISOR_update_va_mapping_otherdomain( unsigned long va, uint64_t new_val, unsigned long flags, domid_t domid) { - uint32_t hi, lo; - - lo = (uint32_t)(new_val & 0xffffffff); - hi = (uint32_t)(new_val >> 32); - - return _hypercall5(int, update_va_mapping_otherdomain, va, - lo, hi, flags, domid); + return _hypercall4(int, update_va_mapping_otherdomain, va, + new_val, flags, domid); } -static inline int +static inline int __must_check HYPERVISOR_vm_assist( unsigned int cmd, unsigned int type) { return _hypercall2(int, vm_assist, cmd, type); } -static inline int +static inline int __must_check HYPERVISOR_vcpu_op( - int cmd, int vcpuid, void *extra_args) + int cmd, unsigned int vcpuid, void *extra_args) { return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args); } -static inline int +static inline int __must_check +HYPERVISOR_set_segment_base( + int reg, unsigned long value) +{ + return _hypercall2(int, set_segment_base, reg, value); +} + +static inline int __must_check HYPERVISOR_suspend( unsigned long srec) { struct sched_shutdown sched_shutdown = { .reason = SHUTDOWN_suspend }; + int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown, - &sched_shutdown, srec); + &sched_shutdown, srec); + #if CONFIG_XEN_COMPAT <= 0x030002 if (rc == -ENOXENSYS) rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown, SHUTDOWN_suspend, srec); -#endif - return (rc); +#endif + + return rc; } #if CONFIG_XEN_COMPAT <= 0x030002 static inline int HYPERVISOR_nmi_op( - unsigned long op, void *arg) + unsigned long op, void *arg) { - return _hypercall2(int, nmi_op, op, arg); + return _hypercall2(int, nmi_op, op, arg); } #endif -static inline int -HYPERVISOR_callback_op( - int cmd, void *arg) -{ - return _hypercall2(int, callback_op, cmd, arg); -} - #ifndef CONFIG_XEN -static inline unsigned long +static inline unsigned long __must_check HYPERVISOR_hvm_op( int op, void *arg) { @@ -379,27 +389,27 @@ HYPERVISOR_hvm_op( } #endif -static inline int +static inline int __must_check +HYPERVISOR_callback_op( + int cmd, const void *arg) +{ + return _hypercall2(int, callback_op, cmd, arg); +} + +static inline int __must_check HYPERVISOR_xenoprof_op( - int op, void *arg) + int op, void *arg) { - return _hypercall2(int, xenoprof_op, op, arg); + return _hypercall2(int, xenoprof_op, op, arg); } -static inline int +static inline int __must_check HYPERVISOR_kexec_op( - unsigned long op, void *args) + unsigned long op, void *args) { - return _hypercall2(int, kexec_op, op, args); + return _hypercall2(int, kexec_op, op, args); } -#endif /* __HYPERCALL_H__ */ -/* - * Local variables: - * c-file-style: "linux" - * indent-tabs-mode: t - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 - * End: - */ +#undef __must_check + +#endif /* __HYPERCALL_H__ */ Modified: user/dfr/xenhvm/6/sys/amd64/include/xen/hypervisor.h ============================================================================== --- user/dfr/xenhvm/6/sys/i386/include/xen/hypervisor.h Sat Nov 22 16:14:52 2008 (r185181) +++ user/dfr/xenhvm/6/sys/amd64/include/xen/hypervisor.h Fri Nov 28 15:49:36 2008 (r185386) @@ -9,8 +9,16 @@ #ifndef __HYPERVISOR_H__ #define __HYPERVISOR_H__ +#ifdef XENHVM + +#define is_running_on_xen() (HYPERVISOR_shared_info != NULL) + +#else + #define is_running_on_xen() 1 +#endif + #ifdef PAE #ifndef CONFIG_X86_PAE #define CONFIG_X86_PAE @@ -42,7 +50,9 @@ #define is_initial_xendomain() 0 #endif +#ifndef XENHVM extern start_info_t *xen_start_info; +#endif extern uint64_t get_system_time(int ticks); @@ -130,7 +140,7 @@ MULTI_update_va_mapping( mcl->op = __HYPERVISOR_update_va_mapping; mcl->args[0] = va; #if defined(__amd64__) - mcl->args[1] = new_val.pte; + mcl->args[1] = new_val; #elif defined(PAE) mcl->args[1] = (uint32_t)(new_val & 0xffffffff) ; mcl->args[2] = (uint32_t)(new_val >> 32); Modified: user/dfr/xenhvm/6/sys/amd64/include/xen/synch_bitops.h ============================================================================== --- user/dfr/xenhvm/6/sys/i386/include/xen/synch_bitops.h Sat Nov 22 16:14:52 2008 (r185181) +++ user/dfr/xenhvm/6/sys/amd64/include/xen/synch_bitops.h Fri Nov 28 15:49:36 2008 (r185386) @@ -88,7 +88,6 @@ static inline unsigned long __synch_cmpx "0"(old) : "memory"); return prev; -#ifdef CONFIG_X86_64 case 4: __asm__ __volatile__("lock; cmpxchgl %k1,%2" : "=a"(prev) @@ -103,15 +102,6 @@ static inline unsigned long __synch_cmpx "0"(old) : "memory"); return prev; -#else - case 4: - __asm__ __volatile__("lock; cmpxchgl %1,%2" - : "=a"(prev) - : "q"(new), "m"(*__synch_xg(ptr)), - "0"(old) - : "memory"); - return prev; -#endif } return old; } Modified: user/dfr/xenhvm/6/sys/amd64/include/xen/xen-os.h ============================================================================== --- user/dfr/xenhvm/6/sys/i386/include/xen/xen-os.h Sat Nov 22 16:14:52 2008 (r185181) +++ user/dfr/xenhvm/6/sys/amd64/include/xen/xen-os.h Fri Nov 28 15:49:36 2008 (r185386) @@ -11,7 +11,7 @@ #define CONFIG_X86_PAE #endif -#if defined(XEN) && !defined(__XEN_INTERFACE_VERSION__) +#if !defined(__XEN_INTERFACE_VERSION__) /* * Can update to a more recent version when we implement * the hypercall page @@ -51,7 +51,7 @@ smp_processor_id(void) #endif #ifndef PANIC_IF -#define PANIC_IF(exp) if (unlikely(exp)) {printk("panic - %s: %s:%d\n",#exp, __FILE__, __LINE__); panic("%s: %s:%d", #exp, __FILE__, __LINE__);} +#define PANIC_IF(exp) if (unlikely(exp)) {panic("%s: %s:%d", #exp, __FILE__, __LINE__);} #endif extern shared_info_t *HYPERVISOR_shared_info; @@ -91,16 +91,17 @@ void printk(const char *fmt, ...); /* some function prototypes */ void trap_init(void); +#define likely(x) __builtin_expect((x),1) +#define unlikely(x) __builtin_expect((x),0) + +#ifndef XENHVM + /* * STI/CLI equivalents. These basically set and clear the virtual * event_enable flag in teh shared_info structure. Note that when * the enable bit is set, there may be pending events to be handled. * We may therefore call into do_hypervisor_callback() directly. */ -#define likely(x) __builtin_expect((x),1) -#define unlikely(x) __builtin_expect((x),0) - - #define __cli() \ do { \ @@ -163,12 +164,14 @@ do { #define spin_lock_irqsave mtx_lock_irqsave #define spin_unlock_irqrestore mtx_unlock_irqrestore +#else +#endif #ifndef mb -#define mb() __asm__ __volatile__("lock; addl $0, 0(%%esp)": : :"memory") +#define mb() __asm__ __volatile__("mfence":::"memory") #endif #ifndef rmb -#define rmb() mb() +#define rmb() __asm__ __volatile__("lfence":::"memory"); #endif #ifndef wmb #define wmb() barrier() Modified: user/dfr/xenhvm/6/sys/amd64/include/xen/xenfunc.h ============================================================================== --- user/dfr/xenhvm/6/sys/i386/include/xen/xenfunc.h Sat Nov 22 16:14:52 2008 (r185181) +++ user/dfr/xenhvm/6/sys/amd64/include/xen/xenfunc.h Fri Nov 28 15:49:36 2008 (r185386) @@ -32,8 +32,12 @@ #include #include +#ifdef XENHVM +#include +#else #include #include +#endif #include #define BKPT __asm__("int3"); #define XPQ_CALL_DEPTH 5 @@ -63,7 +67,9 @@ void _xen_machphys_update(vm_paddr_t, vm #define xen_machphys_update(a, b) _xen_machphys_update((a), (b), NULL, 0) #endif +#ifndef XENHVM void xen_update_descriptor(union descriptor *, union descriptor *); +#endif extern struct mtx balloon_lock; #if 0 Modified: user/dfr/xenhvm/6/sys/amd64/include/xen/xenvar.h ============================================================================== --- user/dfr/xenhvm/6/sys/i386/include/xen/xenvar.h Sat Nov 22 16:14:52 2008 (r185181) +++ user/dfr/xenhvm/6/sys/amd64/include/xen/xenvar.h Fri Nov 28 15:49:36 2008 (r185386) @@ -39,8 +39,6 @@ extern int xendebug_flags; #endif #include -extern xen_pfn_t *xen_phys_machine; - #if 0 #define TRACE_ENTER XENPRINTF("(file=%s, line=%d) entered %s\n", __FILE__, __LINE__, __FUNCTION__) #define TRACE_EXIT XENPRINTF("(file=%s, line=%d) exiting %s\n", __FILE__, __LINE__, __FUNCTION__) @@ -52,6 +50,33 @@ if (xendebug_flags & argflags) XENPRINTF #define TRACE_DEBUG(argflags, _f, _a...) #endif +#ifdef XENHVM + +static inline vm_paddr_t +phystomach(vm_paddr_t pa) +{ + + return (pa); +} + +static inline vm_paddr_t +machtophys(vm_paddr_t ma) +{ + + return (ma); +} + +#define vtomach(va) pmap_kextract((vm_offset_t) (va)) +#define PFNTOMFN(pa) (pa) + +#define set_phys_to_machine(pfn, mfn) ((void)0) +#define PT_UPDATES_FLUSH() ((void)0) + +#else + +extern xen_pfn_t *xen_phys_machine; + + extern xen_pfn_t *xen_machine_phys; /* Xen starts physical pages after the 4MB ISA hole - * FreeBSD doesn't @@ -84,6 +109,8 @@ extern xen_pfn_t *xen_machine_phys; #define phystomach(pa) (((vm_paddr_t)(PFNTOMFN((pa) >> PAGE_SHIFT))) << PAGE_SHIFT) #define machtophys(ma) (((vm_paddr_t)(MFNTOPFN((ma) >> PAGE_SHIFT))) << PAGE_SHIFT) +#endif + void xpq_init(void); From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 15:50:36 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0B12E106564A; Fri, 28 Nov 2008 15:50:36 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id F17B38FC13; Fri, 28 Nov 2008 15:50:35 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASFoZGO022892; Fri, 28 Nov 2008 15:50:35 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASFoZtx022889; Fri, 28 Nov 2008 15:50:35 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281550.mASFoZtx022889@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 15:50:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185387 - user/dfr/xenhvm/6/sys/dev/xen/xenpci X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 15:50:36 -0000 Author: dfr Date: Fri Nov 28 15:50:35 2008 New Revision: 185387 URL: http://svn.freebsd.org/changeset/base/185387 Log: Add a driver the the Xen HVM special platform device. Added: user/dfr/xenhvm/6/sys/dev/xen/xenpci/ user/dfr/xenhvm/6/sys/dev/xen/xenpci/evtchn.c user/dfr/xenhvm/6/sys/dev/xen/xenpci/xenpci.c user/dfr/xenhvm/6/sys/dev/xen/xenpci/xenpcivar.h Added: user/dfr/xenhvm/6/sys/dev/xen/xenpci/evtchn.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/dfr/xenhvm/6/sys/dev/xen/xenpci/evtchn.c Fri Nov 28 15:50:35 2008 (r185387) @@ -0,0 +1,377 @@ +/****************************************************************************** + * evtchn.c + * + * A simplified event channel for para-drivers in unmodified linux + * + * Copyright (c) 2002-2005, K A Fraser + * Copyright (c) 2005, Intel Corporation + * + * This file may be distributed separately from the Linux kernel, or + * incorporated into other software packages, subject to the following license: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this source file (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, modify, + * merge, publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +__FBSDID("$FreeBSD: user/dfr/xenhvm/6/sys/xen/evtchn/evtchn.c 184235 2008-10-25 00:25:25Z kmacy $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +static inline unsigned long __ffs(unsigned long word) +{ + __asm__("bsfq %1,%0" + :"=r" (word) + :"rm" (word)); + return word; +} + +#define is_valid_evtchn(x) ((x) != 0) +#define evtchn_from_irq(x) (irq_evtchn[irq].evtchn) + +static struct { + struct mtx lock; + driver_intr_t *handler; + void *arg; + int evtchn; + int close:1; /* close on unbind_from_irqhandler()? */ + int inuse:1; + int in_handler:1; +} irq_evtchn[256]; +static int evtchn_to_irq[NR_EVENT_CHANNELS] = { + [0 ... NR_EVENT_CHANNELS-1] = -1 }; + +static struct mtx irq_alloc_lock; + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) + +static int alloc_xen_irq(void) +{ + static int warned; + int irq; + + mtx_lock(&irq_alloc_lock); + + for (irq = 1; irq < ARRAY_SIZE(irq_evtchn); irq++) { + if (irq_evtchn[irq].inuse) + continue; + irq_evtchn[irq].inuse = 1; + mtx_unlock(&irq_alloc_lock); + return irq; + } + + if (!warned) { + warned = 1; + printf("alloc_xen_irq: No available IRQ to bind to: " + "increase irq_evtchn[] size in evtchn.c.\n"); + } + + mtx_unlock(&irq_alloc_lock); + + return -ENOSPC; +} + +static void free_xen_irq(int irq) +{ + mtx_lock(&irq_alloc_lock); + irq_evtchn[irq].inuse = 0; + mtx_unlock(&irq_alloc_lock); +} + +int irq_to_evtchn_port(int irq) +{ + return irq_evtchn[irq].evtchn; +} + +void mask_evtchn(int port) +{ + shared_info_t *s = HYPERVISOR_shared_info; + synch_set_bit(port, &s->evtchn_mask[0]); +} + +void unmask_evtchn(int port) +{ + evtchn_unmask_t op = { .port = port }; + HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &op); +} + +int bind_listening_port_to_irqhandler( + unsigned int remote_domain, + const char *devname, + driver_intr_t handler, + void *arg, + unsigned long irqflags, + void **cookiep) +{ + struct evtchn_alloc_unbound alloc_unbound; + int err, irq; + + irq = alloc_xen_irq(); + if (irq < 0) + return irq; + + mtx_lock(&irq_evtchn[irq].lock); + + alloc_unbound.dom = DOMID_SELF; + alloc_unbound.remote_dom = remote_domain; + err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, + &alloc_unbound); + if (err) { + mtx_unlock(&irq_evtchn[irq].lock); + free_xen_irq(irq); + return err; + } + + irq_evtchn[irq].handler = handler; + irq_evtchn[irq].arg = arg; + irq_evtchn[irq].evtchn = alloc_unbound.port; + irq_evtchn[irq].close = 1; + + evtchn_to_irq[alloc_unbound.port] = irq; + + unmask_evtchn(alloc_unbound.port); + + mtx_unlock(&irq_evtchn[irq].lock); + + return irq; +} + +int bind_caller_port_to_irqhandler( + unsigned int caller_port, + const char *devname, + driver_intr_t handler, + void *arg, + unsigned long irqflags, + void **cookiep) +{ + int irq; + + irq = alloc_xen_irq(); + if (irq < 0) + return irq; + + mtx_lock(&irq_evtchn[irq].lock); + + irq_evtchn[irq].handler = handler; + irq_evtchn[irq].arg = arg; + irq_evtchn[irq].evtchn = caller_port; + irq_evtchn[irq].close = 0; + + evtchn_to_irq[caller_port] = irq; + + unmask_evtchn(caller_port); + + mtx_unlock(&irq_evtchn[irq].lock); + + return irq; +} + +void unbind_from_irqhandler(unsigned int irq, void *dev_id) +{ + int evtchn; + + mtx_lock(&irq_evtchn[irq].lock); + + evtchn = evtchn_from_irq(irq); + + if (is_valid_evtchn(evtchn)) { + evtchn_to_irq[evtchn] = -1; + mask_evtchn(evtchn); + if (irq_evtchn[irq].close) { + struct evtchn_close close = { .port = evtchn }; + if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close)) + panic("EVTCHNOP_close failed"); + } + } + + irq_evtchn[irq].handler = NULL; + irq_evtchn[irq].evtchn = 0; + + mtx_unlock(&irq_evtchn[irq].lock); + + while (irq_evtchn[irq].in_handler) + cpu_relax(); + + free_xen_irq(irq); +} + +void notify_remote_via_irq(int irq) +{ + int evtchn; + + evtchn = evtchn_from_irq(irq); + if (is_valid_evtchn(evtchn)) + notify_remote_via_evtchn(evtchn); +} + +static inline unsigned long active_evtchns(unsigned int cpu, shared_info_t *sh, + unsigned int idx) +{ + return (sh->evtchn_pending[idx] & ~sh->evtchn_mask[idx]); +} + +static void +evtchn_interrupt(void *arg) +{ + unsigned int l1i, l2i, port; + unsigned long masked_l1, masked_l2; + /* XXX: All events are bound to vcpu0 but irq may be redirected. */ + int cpu = 0; /*smp_processor_id();*/ + driver_intr_t *handler; + void *handler_arg; + int irq; + shared_info_t *s = HYPERVISOR_shared_info; + vcpu_info_t *v = &s->vcpu_info[cpu]; + unsigned long l1, l2; + + v->evtchn_upcall_pending = 0; + +#if 0 +#ifndef CONFIG_X86 /* No need for a barrier -- XCHG is a barrier on x86. */ + /* Clear master flag /before/ clearing selector flag. */ + wmb(); +#endif +#endif + + l1 = atomic_readandclear_long(&v->evtchn_pending_sel); + + l1i = per_cpu(last_processed_l1i, cpu); + l2i = per_cpu(last_processed_l2i, cpu); + + while (l1 != 0) { + + l1i = (l1i + 1) % BITS_PER_LONG; + masked_l1 = l1 & ((~0UL) << l1i); + + if (masked_l1 == 0) { /* if we masked out all events, wrap around to the beginning */ + l1i = BITS_PER_LONG - 1; + l2i = BITS_PER_LONG - 1; + continue; + } + l1i = __ffs(masked_l1); + + do { + l2 = active_evtchns(cpu, s, l1i); + + l2i = (l2i + 1) % BITS_PER_LONG; + masked_l2 = l2 & ((~0UL) << l2i); + + if (masked_l2 == 0) { /* if we masked out all events, move on */ + l2i = BITS_PER_LONG - 1; + break; + } + l2i = __ffs(masked_l2); + + /* process port */ + port = (l1i * BITS_PER_LONG) + l2i; + synch_clear_bit(port, &s->evtchn_pending[0]); + + irq = evtchn_to_irq[port]; + if (irq < 0) + continue; + + mtx_lock(&irq_evtchn[irq].lock); + handler = irq_evtchn[irq].handler; + handler_arg = irq_evtchn[irq].arg; + if (unlikely(handler == NULL)) { + printk("Xen IRQ%d (port %d) has no handler!\n", + irq, port); + mtx_unlock(&irq_evtchn[irq].lock); + continue; + } + irq_evtchn[irq].in_handler = 1; + mtx_unlock(&irq_evtchn[irq].lock); + + //local_irq_enable(); + handler(handler_arg); + //local_irq_disable(); + + mtx_lock(&irq_evtchn[irq].lock); + irq_evtchn[irq].in_handler = 0; + mtx_unlock(&irq_evtchn[irq].lock); + + /* if this is the final port processed, we'll pick up here+1 next time */ + per_cpu(last_processed_l1i, cpu) = l1i; + per_cpu(last_processed_l2i, cpu) = l2i; + + } while (l2i != BITS_PER_LONG - 1); + + l2 = active_evtchns(cpu, s, l1i); + if (l2 == 0) /* we handled all ports, so we can clear the selector bit */ + l1 &= ~(1UL << l1i); + } +} + +void irq_resume(void) +{ + int evtchn, irq; + + for (evtchn = 0; evtchn < NR_EVENT_CHANNELS; evtchn++) { + mask_evtchn(evtchn); + evtchn_to_irq[evtchn] = -1; + } + + for (irq = 0; irq < ARRAY_SIZE(irq_evtchn); irq++) + irq_evtchn[irq].evtchn = 0; +} + +int +xenpci_irq_init(device_t device, struct xenpci_softc *scp) +{ + int irq, cpu; + int error; + + mtx_init(&irq_alloc_lock, "xen-irq-lock", NULL, MTX_DEF); + + for (irq = 0; irq < ARRAY_SIZE(irq_evtchn); irq++) + mtx_init(&irq_evtchn[irq].lock, "irq-evtchn", NULL, MTX_DEF); + + for (cpu = 0; cpu < mp_ncpus; cpu++) { + per_cpu(last_processed_l1i, cpu) = BITS_PER_LONG - 1; + per_cpu(last_processed_l2i, cpu) = BITS_PER_LONG - 1; + } + + error = BUS_SETUP_INTR(device_get_parent(device), device, + scp->res_irq, INTR_TYPE_MISC, evtchn_interrupt, NULL, + &scp->intr_cookie); + if (error) + return (error); + + return (0); +} Added: user/dfr/xenhvm/6/sys/dev/xen/xenpci/xenpci.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/dfr/xenhvm/6/sys/dev/xen/xenpci/xenpci.c Fri Nov 28 15:50:35 2008 (r185387) @@ -0,0 +1,413 @@ +/* + * Copyright (c) [year] [your name] + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +/* + * These variables are used by the rest of the kernel to access the + * hypervisor. + */ +char *hypercall_stubs; +shared_info_t *HYPERVISOR_shared_info; + +/* + * The softc is automatically allocated by the parent bus using the + * size specified in the driver_t declaration below. + */ +#define DEVICE2SOFTC(dev) ((struct xenpci_softc *) device_get_softc(dev)) + +/* Function prototypes (these should all be static). */ +static int xenpci_deallocate_resources(device_t device); +static int xenpci_allocate_resources(device_t device); +static int xenpci_attach(device_t device, struct xenpci_softc *scp); +static int xenpci_detach(device_t device, struct xenpci_softc *scp); +static int xenpci_resume(device_t device, struct xenpci_softc *scp); + +static int xenpci_alloc_space_int(struct xenpci_softc *scp, size_t sz, + u_long *pa); + +static devclass_t xenpci_devclass; + +static int xenpci_pci_probe(device_t); +static int xenpci_pci_attach(device_t); +static int xenpci_pci_detach(device_t); +static int xenpci_pci_resume(device_t); + +static device_method_t xenpci_pci_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, xenpci_pci_probe), + DEVMETHOD(device_attach, xenpci_pci_attach), + DEVMETHOD(device_detach, xenpci_pci_detach), + DEVMETHOD(device_resume, xenpci_pci_resume), + { 0, 0 } +}; + +static driver_t xenpci_pci_driver = { + "xenpci", + xenpci_pci_methods, + sizeof(struct xenpci_softc), +}; + +DRIVER_MODULE(xenpci, pci, xenpci_pci_driver, xenpci_devclass, 0, 0); + +static struct _pcsid +{ + u_int32_t type; + const char *desc; +} pci_ids[] = { + { 0x00015853, "XenSource, Inc. Xen Platform Device" }, + { 0x00000000, NULL } +}; + +static int +xenpci_pci_probe (device_t device) +{ + u_int32_t type = pci_get_devid(device); + struct _pcsid *ep = pci_ids; + + while (ep->type && ep->type != type) + ++ep; + if (ep->desc) { + device_set_desc(device, ep->desc); + return (0); + } else + return (ENXIO); +} + +static int +xenpci_pci_attach(device_t device) +{ + int error; + struct xenpci_softc *scp = DEVICE2SOFTC(device); + + error = xenpci_attach(device, scp); + if (error) + xenpci_pci_detach(device); + return (error); +} + +static int +xenpci_pci_detach (device_t device) +{ + struct xenpci_softc *scp = DEVICE2SOFTC(device); + + return (xenpci_detach(device, scp)); +} + +static int +xenpci_pci_resume(device_t device) +{ + struct xenpci_softc *scp = DEVICE2SOFTC(device); + + return (xenpci_resume(device, scp)); +} + +/* + * Common Attachment sub-functions + */ +static uint32_t +xenpci_cpuid_base(void) +{ + uint32_t base, regs[4]; + + for (base = 0x40000000; base < 0x40001000; base += 0x100) { + do_cpuid(base, regs); + if (!memcmp("XenVMMXenVMM", ®s[1], 12) + && (regs[0] - base) >= 2) + return (base); + } + return (0); +} + +static int +xenpci_init_hypercall_stubs(device_t device, struct xenpci_softc * scp) +{ + uint32_t base, regs[4]; + int i; + + base = xenpci_cpuid_base(); + if (!base) { + device_printf(device, "Xen platform device but not Xen VMM\n"); + return (EINVAL); + } + + if (bootverbose) { + do_cpuid(base + 1, regs); + device_printf(device, "Xen version %d.%d.\n", + regs[0] >> 16, regs[0] & 0xffff); + } + + /* + * Find the hypercall pages. + */ + do_cpuid(base + 2, regs); + + hypercall_stubs = malloc(regs[0] * PAGE_SIZE, M_TEMP, M_WAITOK); + + for (i = 0; i < regs[0]; i++) { + wrmsr(regs[1], vtophys(hypercall_stubs + i * PAGE_SIZE) + i); + } + + return (0); +} + +static void +xenpci_resume_hypercall_stubs(device_t device, struct xenpci_softc * scp) +{ + uint32_t base, regs[4]; + int i; + + base = xenpci_cpuid_base(); + + do_cpuid(base + 2, regs); + for (i = 0; i < regs[0]; i++) { + wrmsr(regs[1], vtophys(hypercall_stubs + i * PAGE_SIZE) + i); + } +} + +static void +xenpci_set_callback(device_t device) +{ + int irq; + uint64_t callback; + struct xen_hvm_param xhp; + + irq = pci_get_irq(device); + if (irq < 16) { + callback = irq; + } else { + callback = (pci_get_intpin(device) - 1) & 3; + callback |= pci_get_slot(device) << 11; + callback |= 1ull << 56; + } + + xhp.domid = DOMID_SELF; + xhp.index = HVM_PARAM_CALLBACK_IRQ; + xhp.value = callback; + if (HYPERVISOR_hvm_op(HVMOP_set_param, &xhp)) + panic("Can't set evtchn callback"); +} + +static int +xenpci_attach(device_t device, struct xenpci_softc * scp) +{ + struct xen_add_to_physmap xatp; + u_long shared_pa; + + if (xenpci_allocate_resources(device)) + goto errexit; + + scp->phys_next = rman_get_start(scp->res_memory); + + if (xenpci_init_hypercall_stubs(device, scp)) + goto errexit; + + setup_xen_features(); + + xenpci_alloc_space_int(scp, PAGE_SIZE, &shared_pa); + + xatp.domid = DOMID_SELF; + xatp.idx = 0; + xatp.space = XENMAPSPACE_shared_info; + xatp.gpfn = shared_pa >> PAGE_SHIFT; + if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp)) + panic("HYPERVISOR_memory_op failed"); + + HYPERVISOR_shared_info = pmap_mapdev(shared_pa, PAGE_SIZE); + + /* + * Hook the irq up to evtchn + */ + xenpci_irq_init(device, scp); + xenpci_set_callback(device); + + device_add_child(device, "xenbus", 0); + + return (bus_generic_attach(device)); + +errexit: + /* + * Undo anything we may have done. + */ + xenpci_detach(device, scp); + return (ENXIO); +} + +static int +xenpci_detach(device_t device, struct xenpci_softc *scp) +{ + device_t parent = device_get_parent(device); + + /* + * Take our interrupt handler out of the list of handlers + * that can handle this irq. + */ + if (scp->intr_cookie != NULL) { + if (BUS_TEARDOWN_INTR(parent, device, + scp->res_irq, scp->intr_cookie) != 0) + printf("intr teardown failed.. continuing\n"); + scp->intr_cookie = NULL; + } + + /* + * Deallocate any system resources we may have + * allocated on behalf of this driver. + */ + return xenpci_deallocate_resources(device); +} + +static int +xenpci_resume(device_t device, struct xenpci_softc *scp) +{ + + xenpci_resume_hypercall_stubs(device, scp); +} + +static int +xenpci_allocate_resources(device_t device) +{ + int error; + struct xenpci_softc *scp = DEVICE2SOFTC(device); + + scp->res_irq = bus_alloc_resource_any(device, SYS_RES_IRQ, + &scp->rid_irq, RF_SHAREABLE|RF_ACTIVE); + if (scp->res_irq == NULL) + goto errexit; + + scp->rid_ioport = PCIR_BAR(0); + scp->res_ioport = bus_alloc_resource_any(device, SYS_RES_IOPORT, + &scp->rid_ioport, RF_ACTIVE); + if (scp->res_ioport == NULL) + goto errexit; + + scp->rid_memory = PCIR_BAR(1); + scp->res_memory = bus_alloc_resource_any(device, SYS_RES_MEMORY, + &scp->rid_memory, RF_ACTIVE); + if (scp->res_memory == NULL) + goto errexit; + return (0); + +errexit: + error = ENXIO; + /* Cleanup anything we may have assigned. */ + xenpci_deallocate_resources(device); + return (ENXIO); /* For want of a better idea. */ +} + +static int +xenpci_deallocate_resources(device_t device) +{ + struct xenpci_softc *scp = DEVICE2SOFTC(device); + + if (scp->res_irq != 0) { + bus_deactivate_resource(device, SYS_RES_IRQ, + scp->rid_irq, scp->res_irq); + bus_release_resource(device, SYS_RES_IRQ, + scp->rid_irq, scp->res_irq); + scp->res_irq = 0; + } + if (scp->res_ioport != 0) { + bus_deactivate_resource(device, SYS_RES_IOPORT, + scp->rid_ioport, scp->res_ioport); + bus_release_resource(device, SYS_RES_IOPORT, + scp->rid_ioport, scp->res_ioport); + scp->res_ioport = 0; + } + if (scp->res_memory != 0) { + bus_deactivate_resource(device, SYS_RES_MEMORY, + scp->rid_memory, scp->res_memory); + bus_release_resource(device, SYS_RES_MEMORY, + scp->rid_memory, scp->res_memory); + scp->res_memory = 0; + } + + return (0); +} + +static int +xenpci_alloc_space_int(struct xenpci_softc *scp, size_t sz, u_long *pa) +{ + + if (scp->phys_next + sz > rman_get_end(scp->res_memory)) { + return (ENOMEM); + } + + *pa = scp->phys_next; + scp->phys_next += sz; + + return (0); +} + +int +xenpci_alloc_space(size_t sz, u_long *pa) +{ + device_t device = devclass_get_device(xenpci_devclass, 0); + + if (device) { + return (xenpci_alloc_space_int(DEVICE2SOFTC(device), + sz, pa)); + } else { + return (ENOMEM); + } +} + +void +printk(const char *fmt, ...) +{ + __va_list ap; + + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); +} Added: user/dfr/xenhvm/6/sys/dev/xen/xenpci/xenpcivar.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/dfr/xenhvm/6/sys/dev/xen/xenpci/xenpcivar.h Fri Nov 28 15:50:35 2008 (r185387) @@ -0,0 +1,43 @@ +/* + * Copyright (c) [year] [your name] + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * One of these per allocated device. + */ +struct xenpci_softc { + int rid_ioport; + int rid_memory; + int rid_irq; + struct resource* res_ioport; /* Resource for port range. */ + struct resource* res_memory; /* Resource for mem range. */ + struct resource* res_irq; /* Resource for irq range. */ + void *intr_cookie; + + u_long phys_next; /* next page from mem range */ +}; + +extern int xenpci_irq_init(device_t device, struct xenpci_softc *scp); +extern int xenpci_alloc_space(size_t sz, u_long *pa); From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 16:25:44 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 22A891065674; Fri, 28 Nov 2008 16:25:44 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 160278FC25; Fri, 28 Nov 2008 16:25:44 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASGPhSt023572; Fri, 28 Nov 2008 16:25:43 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASGPhBc023570; Fri, 28 Nov 2008 16:25:43 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281625.mASGPhBc023570@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 16:25:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185388 - user/dfr/xenhvm/6/sys/xen X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 16:25:44 -0000 Author: dfr Date: Fri Nov 28 16:25:43 2008 New Revision: 185388 URL: http://svn.freebsd.org/changeset/base/185388 Log: Add Xen HVM support. Modified: user/dfr/xenhvm/6/sys/xen/gnttab.c user/dfr/xenhvm/6/sys/xen/gnttab.h Modified: user/dfr/xenhvm/6/sys/xen/gnttab.c ============================================================================== --- user/dfr/xenhvm/6/sys/xen/gnttab.c Fri Nov 28 15:50:35 2008 (r185387) +++ user/dfr/xenhvm/6/sys/xen/gnttab.c Fri Nov 28 16:25:43 2008 (r185388) @@ -452,6 +452,8 @@ unmap_pte_fn(pte_t *pte, struct page *pm } #endif +#ifndef XENHVM + static int gnttab_map(unsigned int start_idx, unsigned int end_idx) { @@ -484,6 +486,8 @@ gnttab_map(unsigned int start_idx, unsig PANIC_IF(area == 0); shared = (grant_entry_t *)area; } + + for (i = 0; i < nr_gframes; i++) PT_SET_MA(((caddr_t)shared) + i*PAGE_SIZE, ((vm_paddr_t)frames[i]) << PAGE_SHIFT | PG_RW | PG_V); @@ -514,6 +518,59 @@ gnttab_suspend(void) return (0); } +#else /* XENHVM */ + +#include + +static unsigned long resume_frames; + +static int gnttab_map(unsigned int start_idx, unsigned int end_idx) +{ + struct xen_add_to_physmap xatp; + unsigned int i = end_idx; + + /* Loop backwards, so that the first hypercall has the largest index, + * ensuring that the table will grow only once. + */ + do { + xatp.domid = DOMID_SELF; + xatp.idx = i; + xatp.space = XENMAPSPACE_grant_table; + xatp.gpfn = (resume_frames >> PAGE_SHIFT) + i; + if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp)) + panic("HYPERVISOR_memory_op failed to map gnttab"); + } while (i-- > start_idx); + + shared = pmap_mapdev(resume_frames, (end_idx + 1) * PAGE_SIZE); + + return (0); +} + +int +gnttab_resume(void) +{ + int error; + unsigned int max_nr_gframes, nr_gframes; + + nr_gframes = nr_grant_frames; + max_nr_gframes = max_nr_grant_frames(); + if (max_nr_gframes < nr_gframes) + return -ENOSYS; + + if (!resume_frames) { + error = xenpci_alloc_space(PAGE_SIZE * max_nr_gframes, + &resume_frames); + if (error) { + printf("error mapping gnttab share frames\n"); + return (error); + } + } + + return (gnttab_map(0, nr_gframes - 1)); +} + +#endif + static int gnttab_expand(unsigned int req_entries) { @@ -564,7 +621,7 @@ gnttab_init(void *unused) goto ini_nomem; } - if (gnttab_resume() < 0) + if (gnttab_resume()) return -ENODEV; nr_init_grefs = nr_grant_frames * GREFS_PER_GRANT_FRAME; @@ -576,7 +633,8 @@ gnttab_init(void *unused) gnttab_free_count = nr_init_grefs - NR_RESERVED_ENTRIES; gnttab_free_head = NR_RESERVED_ENTRIES; - printk("Grant table initialized\n"); + if (bootverbose) + printf("Grant table initialized\n"); return 0; ini_nomem: Modified: user/dfr/xenhvm/6/sys/xen/gnttab.h ============================================================================== --- user/dfr/xenhvm/6/sys/xen/gnttab.h Fri Nov 28 15:50:35 2008 (r185387) +++ user/dfr/xenhvm/6/sys/xen/gnttab.h Fri Nov 28 16:25:43 2008 (r185388) @@ -43,6 +43,7 @@ #include #include +#include #include #include #include From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 16:26:29 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7713A1065672; Fri, 28 Nov 2008 16:26:29 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6A9B38FC12; Fri, 28 Nov 2008 16:26:29 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASGQTXd023624; Fri, 28 Nov 2008 16:26:29 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASGQTXn023622; Fri, 28 Nov 2008 16:26:29 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281626.mASGQTXn023622@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 16:26:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185389 - user/dfr/xenhvm/6/sys/conf X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 16:26:29 -0000 Author: dfr Date: Fri Nov 28 16:26:29 2008 New Revision: 185389 URL: http://svn.freebsd.org/changeset/base/185389 Log: Add Xen HVM support. Modified: user/dfr/xenhvm/6/sys/conf/files user/dfr/xenhvm/6/sys/conf/options.amd64 Modified: user/dfr/xenhvm/6/sys/conf/files ============================================================================== --- user/dfr/xenhvm/6/sys/conf/files Fri Nov 28 16:25:43 2008 (r185388) +++ user/dfr/xenhvm/6/sys/conf/files Fri Nov 28 16:26:29 2008 (r185389) @@ -2061,3 +2061,22 @@ dev/xen/console/console.c optional dev/xen/console/xencons_ring.c optional xen dev/xen/blkfront/blkfront.c optional xen dev/xen/netfront/netfront.c optional xen +dev/xen/blkfront/blkfront.c optional xenhvm +dev/xen/netfront/netfront.c optional xenhvm + +xen/gnttab.c optional xenhvm +xen/features.c optional xenhvm +dev/xen/xenpci/evtchn.c optional xenhvm +xen/evtchn/evtchn_dev.c optional xenhvm +xen/xenbus/xenbus_client.c optional xenhvm +xen/xenbus/xenbus_comms.c optional xenhvm +xen/xenbus/xenbus_dev.c optional xenhvm +#xen/xenbus/xenbus_newbus.c optional xenhvm +xen/xenbus/xenbus_probe.c optional xenhvm +xen/xenbus/xenbus_probe_backend.c optional xenhvm +xen/xenbus/xenbus_xs.c optional xenhvm +#dev/xen/console/console.c optional xenhvm +#dev/xen/console/xencons_ring.c optional xenhvm +#dev/xen/blkfront/blkfront.c optional xenhvm +#dev/xen/netfront/netfront.c optional xenhvm +dev/xen/xenpci/xenpci.c optional xenpci Modified: user/dfr/xenhvm/6/sys/conf/options.amd64 ============================================================================== --- user/dfr/xenhvm/6/sys/conf/options.amd64 Fri Nov 28 16:25:43 2008 (r185388) +++ user/dfr/xenhvm/6/sys/conf/options.amd64 Fri Nov 28 16:26:29 2008 (r185389) @@ -58,3 +58,5 @@ DEV_ATPIC opt_atpic.h # Debugging KDB_STOP_NMI opt_kdb.h + +XENHVM opt_global.h From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 16:27:25 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DF040106564A; Fri, 28 Nov 2008 16:27:25 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D280D8FC0C; Fri, 28 Nov 2008 16:27:25 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASGRPoK023679; Fri, 28 Nov 2008 16:27:25 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASGRPmE023678; Fri, 28 Nov 2008 16:27:25 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281627.mASGRPmE023678@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 16:27:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185390 - user/dfr/xenhvm/6/sys/xen/interface/hvm X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 16:27:26 -0000 Author: dfr Date: Fri Nov 28 16:27:25 2008 New Revision: 185390 URL: http://svn.freebsd.org/changeset/base/185390 Log: Make this compile in the kernel build environment. Modified: user/dfr/xenhvm/6/sys/xen/interface/hvm/params.h Modified: user/dfr/xenhvm/6/sys/xen/interface/hvm/params.h ============================================================================== --- user/dfr/xenhvm/6/sys/xen/interface/hvm/params.h Fri Nov 28 16:26:29 2008 (r185389) +++ user/dfr/xenhvm/6/sys/xen/interface/hvm/params.h Fri Nov 28 16:27:25 2008 (r185390) @@ -21,7 +21,7 @@ #ifndef __XEN_PUBLIC_HVM_PARAMS_H__ #define __XEN_PUBLIC_HVM_PARAMS_H__ -#include "hvm_op.h" +#include /* * Parameter space for HVMOP_{set,get}_param. From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 16:28:04 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DFCA21065674; Fri, 28 Nov 2008 16:28:04 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D32358FC1B; Fri, 28 Nov 2008 16:28:04 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASGS4gR023730; Fri, 28 Nov 2008 16:28:04 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASGS4VW023729; Fri, 28 Nov 2008 16:28:04 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281628.mASGS4VW023729@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 16:28:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185391 - user/dfr/xenhvm/6/sys/xen/interface/arch-x86 X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 16:28:05 -0000 Author: dfr Date: Fri Nov 28 16:28:04 2008 New Revision: 185391 URL: http://svn.freebsd.org/changeset/base/185391 Log: Make this build for amd64. Modified: user/dfr/xenhvm/6/sys/xen/interface/arch-x86/xen.h Modified: user/dfr/xenhvm/6/sys/xen/interface/arch-x86/xen.h ============================================================================== --- user/dfr/xenhvm/6/sys/xen/interface/arch-x86/xen.h Fri Nov 28 16:27:25 2008 (r185390) +++ user/dfr/xenhvm/6/sys/xen/interface/arch-x86/xen.h Fri Nov 28 16:28:04 2008 (r185391) @@ -50,7 +50,7 @@ #if defined(__i386__) #include #elif defined(__x86_64__) -#include "xen-x86_64.h" +#include #endif #ifndef __ASSEMBLY__ From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 16:29:25 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4D82D1065675; Fri, 28 Nov 2008 16:29:25 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3EFA08FC0A; Fri, 28 Nov 2008 16:29:25 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASGTPjb023794; Fri, 28 Nov 2008 16:29:25 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASGTP1R023793; Fri, 28 Nov 2008 16:29:25 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281629.mASGTP1R023793@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 16:29:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185392 - user/dfr/xenhvm/6/sys/xen/evtchn X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 16:29:25 -0000 Author: dfr Date: Fri Nov 28 16:29:24 2008 New Revision: 185392 URL: http://svn.freebsd.org/changeset/base/185392 Log: Make this build on amd64. Modified: user/dfr/xenhvm/6/sys/xen/evtchn/evtchn_dev.c Modified: user/dfr/xenhvm/6/sys/xen/evtchn/evtchn_dev.c ============================================================================== --- user/dfr/xenhvm/6/sys/xen/evtchn/evtchn_dev.c Fri Nov 28 16:28:04 2008 (r185391) +++ user/dfr/xenhvm/6/sys/xen/evtchn/evtchn_dev.c Fri Nov 28 16:29:24 2008 (r185392) @@ -234,14 +234,14 @@ evtchn_ioctl(struct cdev *dev, unsigned __evtchn_reset_buffer_ring(); break; case EVTCHN_BIND: - if ( !synch_test_and_set_bit((int)arg, &bound_ports[0]) ) - unmask_evtchn((int)arg); + if ( !synch_test_and_set_bit((uintptr_t)arg, &bound_ports[0]) ) + unmask_evtchn((uintptr_t)arg); else rc = EINVAL; break; case EVTCHN_UNBIND: - if ( synch_test_and_clear_bit((int)arg, &bound_ports[0]) ) - mask_evtchn((int)arg); + if ( synch_test_and_clear_bit((uintptr_t)arg, &bound_ports[0]) ) + mask_evtchn((uintptr_t)arg); else rc = EINVAL; break; From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 16:39:20 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C71591065674; Fri, 28 Nov 2008 16:39:20 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BA30B8FC14; Fri, 28 Nov 2008 16:39:20 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASGdKOT024027; Fri, 28 Nov 2008 16:39:20 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASGdKJg024025; Fri, 28 Nov 2008 16:39:20 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281639.mASGdKJg024025@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 16:39:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185393 - user/dfr/xenhvm/6/sys/xen/xenbus X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 16:39:20 -0000 Author: dfr Date: Fri Nov 28 16:39:20 2008 New Revision: 185393 URL: http://svn.freebsd.org/changeset/base/185393 Log: Add Xen HVM support. Modified: user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_comms.c user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_xs.c Modified: user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_comms.c ============================================================================== --- user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_comms.c Fri Nov 28 16:29:24 2008 (r185392) +++ user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_comms.c Fri Nov 28 16:39:20 2008 (r185393) @@ -58,7 +58,6 @@ extern int xenstored_ready; static DECLARE_WORK(probe_work, xenbus_probe, NULL); #endif int xb_wait; -extern char *xen_store; #define wake_up wakeup #define xb_waitq xb_wait #define pr_debug(a,b,c) @@ -144,7 +143,7 @@ int xb_write(const void *tdata, unsigned intf->req_prod += avail; /* This implies mb() before other side sees interrupt. */ - notify_remote_via_evtchn(xen_start_info->store_evtchn); + notify_remote_via_evtchn(xen_store_evtchn); } return 0; @@ -205,7 +204,7 @@ int xb_read(void *tdata, unsigned len) pr_debug("Finished read of %i bytes (%i to go)\n", avail, len); /* Implies mb(): they will see new header. */ - notify_remote_via_evtchn(xen_start_info->store_evtchn); + notify_remote_via_evtchn(xen_store_evtchn); } return 0; @@ -228,7 +227,7 @@ int xb_init_comms(void) unbind_from_irqhandler(xenbus_irq, &xb_waitq); err = bind_caller_port_to_irqhandler( - xen_start_info->store_evtchn, + xen_store_evtchn, "xenbus", wake_waiting, NULL, INTR_TYPE_NET, NULL); if (err <= 0) { log(LOG_WARNING, "XENBUS request irq failed %i\n", err); Modified: user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_xs.c ============================================================================== --- user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_xs.c Fri Nov 28 16:29:24 2008 (r185392) +++ user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_xs.c Fri Nov 28 16:39:20 2008 (r185393) @@ -57,6 +57,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + static int xs_process_msg(enum xsd_sockmsg_type *type); #define kmalloc(size, unused) malloc(size, M_DEVBUF, M_WAITOK) @@ -71,6 +73,7 @@ static int xs_process_msg(enum xsd_sockm #define streq(a, b) (strcmp((a), (b)) == 0) int xenwatch_running = 0; int xenbus_running = 0; +int xen_store_evtchn; struct kvec { const void *iov_base; @@ -908,11 +911,43 @@ static void xenbus_thread(void *unused) } } +#ifdef XENHVM + +static unsigned long xen_store_mfn; +char *xen_store; + +static inline unsigned long +hvm_get_parameter(int index) +{ + struct xen_hvm_param xhv; + int error; + + xhv.domid = DOMID_SELF; + xhv.index = index; + error = HYPERVISOR_hvm_op(HVMOP_get_param, &xhv); + if (error) { + printf("hvm_get_parameter: failed to get %d, error %d\n", + index, error); + return (0); + } + return (xhv.value); +} + +#endif + int xs_init(void) { int err; struct proc *p; +#ifdef XENHVM + xen_store_evtchn = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN); + xen_store_mfn = hvm_get_parameter(HVM_PARAM_STORE_PFN); + xen_store = pmap_mapdev(xen_store_mfn * PAGE_SIZE, PAGE_SIZE); +#else + xen_store_evtchn = xen_start_info->store_evtchn; +#endif + TAILQ_INIT(&xs_state.reply_list); TAILQ_INIT(&watch_events); sx_init(&xenwatch_mutex, "xenwatch"); From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 16:40:01 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3161D1065674; Fri, 28 Nov 2008 16:40:01 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 033AE8FC19; Fri, 28 Nov 2008 16:40:01 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASGe0Tj024079; Fri, 28 Nov 2008 16:40:00 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASGe0IG024078; Fri, 28 Nov 2008 16:40:00 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281640.mASGe0IG024078@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 16:40:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185394 - user/dfr/xenhvm/6/sys/xen/xenbus X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 16:40:01 -0000 Author: dfr Date: Fri Nov 28 16:40:00 2008 New Revision: 185394 URL: http://svn.freebsd.org/changeset/base/185394 Log: Add Xen HVM support. Modified: user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_comms.h Modified: user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_comms.h ============================================================================== --- user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_comms.h Fri Nov 28 16:39:20 2008 (r185393) +++ user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_comms.h Fri Nov 28 16:40:00 2008 (r185394) @@ -30,6 +30,9 @@ #ifndef _XENBUS_COMMS_H #define _XENBUS_COMMS_H +extern int xen_store_evtchn; +extern char *xen_store; + int xs_init(void); int xb_init_comms(void); From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 16:41:00 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 298E41065673; Fri, 28 Nov 2008 16:41:00 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1CA778FC08; Fri, 28 Nov 2008 16:41:00 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASGexFJ024132; Fri, 28 Nov 2008 16:40:59 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASGexIH024131; Fri, 28 Nov 2008 16:40:59 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281640.mASGexIH024131@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 16:40:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185395 - user/dfr/xenhvm/6/sys/xen/xenbus X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 16:41:00 -0000 Author: dfr Date: Fri Nov 28 16:40:59 2008 New Revision: 185395 URL: http://svn.freebsd.org/changeset/base/185395 Log: Add Xen HVM support. Export some information to userland to help support the userland Xen tools. Modified: user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_probe.c Modified: user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_probe.c ============================================================================== --- user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_probe.c Fri Nov 28 16:40:00 2008 (r185394) +++ user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_probe.c Fri Nov 28 16:40:59 2008 (r185395) @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -929,7 +930,10 @@ void unregister_xenstore_notifier(struct EXPORT_SYMBOL(unregister_xenstore_notifier); #endif - +SYSCTL_DECL(_dev); +SYSCTL_NODE(_dev, OID_AUTO, xen, CTLFLAG_RD, NULL, "Xen"); +SYSCTL_INT(_dev_xen, OID_AUTO, xsd_port, CTLFLAG_RD, &xen_store_evtchn, 0, ""); +SYSCTL_ULONG(_dev_xen, OID_AUTO, xsd_kva, CTLFLAG_RD, (u_long *) &xen_store, 0, ""); #ifdef DOM0 static struct proc_dir_entry *xsd_mfn_intf; @@ -983,13 +987,12 @@ xenbus_probe_sysinit(void *unused) device_register(&xenbus_backend.dev); #endif +#ifdef DOM0 /* ** Domain0 doesn't have a store_evtchn or store_mfn yet. */ - dom0 = (xen_start_info->store_evtchn == 0); + dom0 = (xen_store_evtchn == 0); - -#ifdef DOM0 if (dom0) { unsigned long page; @@ -1025,6 +1028,8 @@ xenbus_probe_sysinit(void *unused) if((xsd_port_intf = create_xen_proc_entry("xsd_port", 0400))) xsd_port_intf->read_proc = xsd_port_read; } +#else + dom0 = FALSE; #endif /* Initialize the interface to xenstore. */ err = xs_init(); From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 16:42:01 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F33E71065672; Fri, 28 Nov 2008 16:42:00 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E65638FC0A; Fri, 28 Nov 2008 16:42:00 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASGg0EZ024185; Fri, 28 Nov 2008 16:42:00 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASGg0pv024184; Fri, 28 Nov 2008 16:42:00 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281642.mASGg0pv024184@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 16:42:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185396 - user/dfr/xenhvm/6/sys/xen/xenbus X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 16:42:01 -0000 Author: dfr Date: Fri Nov 28 16:42:00 2008 New Revision: 185396 URL: http://svn.freebsd.org/changeset/base/185396 Log: Add Xen HVM support. Make the write path to the device actually work. Modified: user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_dev.c Modified: user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_dev.c ============================================================================== --- user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_dev.c Fri Nov 28 16:40:59 2008 (r185395) +++ user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_dev.c Fri Nov 28 16:42:00 2008 (r185396) @@ -124,21 +124,22 @@ static void queue_reply(struct xenbus_de static int xenbus_dev_write(struct cdev *dev, struct uio *uio, int ioflag) { - int err = 0; + int error; struct xenbus_dev_data *u = dev->si_drv1; struct xenbus_dev_transaction *trans; void *reply; - int len = uio->uio_iov[0].iov_len; + int len = uio->uio_resid; if ((len + u->len) > sizeof(u->u.buffer)) return EINVAL; - if (copyin(u->u.buffer + u->len, uio->uio_iov[0].iov_base, len) != 0) - return EFAULT; + error = uiomove(u->u.buffer + u->len, len, uio); + if (error) + return (error); u->len += len; if (u->len < (sizeof(u->u.msg) + u->u.msg.len)) - return len; + return (0); switch (u->u.msg.type) { case XS_TRANSACTION_START: @@ -154,7 +155,7 @@ xenbus_dev_write(struct cdev *dev, struc case XS_SET_PERMS: reply = xenbus_dev_request_and_reply(&u->u.msg); if (IS_ERR(reply)) { - err = PTR_ERR(reply); + error = PTR_ERR(reply); } else { if (u->u.msg.type == XS_TRANSACTION_START) { trans = kmalloc(sizeof(*trans), GFP_KERNEL); @@ -179,23 +180,21 @@ xenbus_dev_write(struct cdev *dev, struc break; default: - err = EINVAL; + error = EINVAL; break; } - if (err == 0) { + if (error == 0) u->len = 0; - err = len; - } - return err; + return (error); } static int xenbus_dev_open(struct cdev *dev, int oflags, int devtype, struct thread *td) { struct xenbus_dev_data *u; - if (xen_start_info->store_evtchn == 0) + if (xen_store_evtchn == 0) return ENOENT; #if 0 /* XXX figure out if equiv needed */ nonseekable_open(inode, filp); @@ -239,7 +238,7 @@ static struct cdevsw xenbus_dev_cdevsw = static int xenbus_dev_sysinit(void) { - make_dev(&xenbus_dev_cdevsw, 0, UID_ROOT, GID_WHEEL, 0400, "xenbus"); + make_dev(&xenbus_dev_cdevsw, 0, UID_ROOT, GID_WHEEL, 0400, "xen/xenbus"); return 0; } From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 16:52:21 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 00E9B1065672; Fri, 28 Nov 2008 16:52:21 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E78D18FC0A; Fri, 28 Nov 2008 16:52:20 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASGqKOS024456; Fri, 28 Nov 2008 16:52:20 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASGqKTN024455; Fri, 28 Nov 2008 16:52:20 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281652.mASGqKTN024455@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 16:52:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185397 - user/dfr/xenhvm/6/sys/xen/xenbus X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 16:52:21 -0000 Author: dfr Date: Fri Nov 28 16:52:20 2008 New Revision: 185397 URL: http://svn.freebsd.org/changeset/base/185397 Log: Remove a load of debug printfs which just get in the way. Modified: user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_xs.c Modified: user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_xs.c ============================================================================== --- user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_xs.c Fri Nov 28 16:42:00 2008 (r185396) +++ user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_xs.c Fri Nov 28 16:52:20 2008 (r185397) @@ -153,9 +153,7 @@ static void *read_reply(enum xsd_sockmsg struct xs_stored_msg *msg; char *body; int i, err; - enum xsd_sockmsg_type itype = *type; - printf("read_reply "); if (xenbus_running == 0) { /* * Give other domain time to run :-/ @@ -195,17 +193,12 @@ static void *read_reply(enum xsd_sockmsg mtx_unlock(&xs_state.reply_lock); - printf("itype=%d htype=%d ", itype, msg->hdr.type); *type = msg->hdr.type; if (len) *len = msg->hdr.len; body = msg->u.reply.body; kfree(msg); - if (len) - printf("len=%d\n", *len); - else - printf("len=NULL\n"); return body; } @@ -277,8 +270,6 @@ static void *xs_talkv(struct xenbus_tran for (i = 0; i < num_vecs; i++) msg.len += iovec[i].iov_len; - printf("xs_talkv "); - sx_xlock(&xs_state.request_mutex); err = xb_write(&msg, sizeof(msg)); @@ -317,14 +308,12 @@ static void *xs_talkv(struct xenbus_tran struct xs_stored_msg *wmsg = TAILQ_FIRST(&watch_events); list_del(&watch_events, wmsg); - printf("handling %p ...", wmsg->u.watch.handle->callback); - wmsg->u.watch.handle->callback( + wmsg->u.watch.handle->callback( wmsg->u.watch.handle, (const char **)wmsg->u.watch.vec, wmsg->u.watch.vec_size); - printf("... %p done\n", wmsg->u.watch.handle->callback); - kfree(wmsg->u.watch.vec); + kfree(wmsg->u.watch.vec); kfree(wmsg); } xenwatch_inline = 0; @@ -342,7 +331,6 @@ static void *xs_single(struct xenbus_tra { struct kvec iovec; - printf("xs_single %s ", string); iovec.iov_base = (const void *)string; iovec.iov_len = strlen(string) + 1; return xs_talkv(t, type, &iovec, 1, len); @@ -460,7 +448,6 @@ void *xenbus_read(struct xenbus_transact if (IS_ERR(path)) return (void *)path; - printf("xs_read "); ret = xs_single(t, XS_READ, path, len); kfree(path); return ret; @@ -486,7 +473,6 @@ int xenbus_write(struct xenbus_transacti iovec[1].iov_base = string; iovec[1].iov_len = strlen(string); - printf("xenbus_write dir=%s val=%s ", dir, string); ret = xs_error(xs_talkv(t, XS_WRITE, iovec, ARRAY_SIZE(iovec), NULL)); kfree(path); return ret; @@ -560,7 +546,6 @@ int xenbus_transaction_end(struct xenbus else strcpy(abortstr, "T"); - printf("xenbus_transaction_end "); err = xs_error(xs_single(t, XS_TRANSACTION_END, abortstr, NULL)); sx_sunlock(&xs_state.suspend_mutex); @@ -628,7 +613,6 @@ int xenbus_gather(struct xenbus_transact for (i = 0; i < 10000; i++) HYPERVISOR_yield(); - printf("gather "); va_start(ap, dir); while (ret == 0 && (name = va_arg(ap, char *)) != NULL) { const char *fmt = va_arg(ap, char *); @@ -640,7 +624,6 @@ int xenbus_gather(struct xenbus_transact ret = PTR_ERR(p); break; } - printf(" %s ", p); if (fmt) { if (sscanf(p, fmt, result) == 0) ret = -EINVAL; @@ -649,7 +632,6 @@ int xenbus_gather(struct xenbus_transact *(char **)result = p; } va_end(ap); - printf("\n"); return ret; } EXPORT_SYMBOL(xenbus_gather); @@ -880,15 +862,12 @@ static int xs_process_msg(enum xsd_sockm } mtx_unlock(&watches_lock); } else { - printf("event=%d ", *type); msg->u.reply.body = body; mtx_lock(&xs_state.reply_lock); TAILQ_INSERT_TAIL(&xs_state.reply_list, msg, list); wakeup(&xs_state.reply_waitq); mtx_unlock(&xs_state.reply_lock); } - if (*type == XS_WATCH_EVENT) - printf("\n"); return 0; } @@ -912,7 +891,6 @@ static void xenbus_thread(void *unused) } #ifdef XENHVM - static unsigned long xen_store_mfn; char *xen_store; From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 17:00:19 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 60EA41065672; Fri, 28 Nov 2008 17:00:19 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5322C8FC1A; Fri, 28 Nov 2008 17:00:19 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASH0JKg024654; Fri, 28 Nov 2008 17:00:19 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASH0Je3024653; Fri, 28 Nov 2008 17:00:19 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281700.mASH0Je3024653@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 17:00:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185398 - user/dfr/xenhvm/6/sys/dev/xen/blkfront X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 17:00:19 -0000 Author: dfr Date: Fri Nov 28 17:00:19 2008 New Revision: 185398 URL: http://svn.freebsd.org/changeset/base/185398 Log: Add some code to choose a disk name and unit number based on the Linux major/minor number passed to us from the backend. This makes life easier when switching back and forth between pure emulated HVM and Xen-aware HVM. Tell the backend what protocol we are using to talk to it - this makes things work properly on amd64. Modified: user/dfr/xenhvm/6/sys/dev/xen/blkfront/blkfront.c Modified: user/dfr/xenhvm/6/sys/dev/xen/blkfront/blkfront.c ============================================================================== --- user/dfr/xenhvm/6/sys/dev/xen/blkfront/blkfront.c Fri Nov 28 16:52:20 2008 (r185397) +++ user/dfr/xenhvm/6/sys/dev/xen/blkfront/blkfront.c Fri Nov 28 17:00:19 2008 (r185398) @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -135,28 +136,96 @@ pfn_to_mfn(vm_paddr_t pfn) return (phystomach(pfn << PAGE_SHIFT) >> PAGE_SHIFT); } +/* + * Translate Linux major/minor to an appropriate name and unit + * number. For HVM guests, this allows us to use the same drive names + * with blkfront as the emulated drives, easing transition slightly. + */ +static void +blkfront_vdevice_to_unit(int vdevice, int *unit, const char **name) +{ + static struct vdev_info { + int major; + int shift; + int base; + const char *name; + } info[] = { + {3, 6, 0, "ad"}, /* ide0 */ + {22, 6, 2, "ad"}, /* ide1 */ + {33, 6, 4, "ad"}, /* ide2 */ + {34, 6, 6, "ad"}, /* ide3 */ + {56, 6, 8, "ad"}, /* ide4 */ + {57, 6, 10, "ad"}, /* ide5 */ + {88, 6, 12, "ad"}, /* ide6 */ + {89, 6, 14, "ad"}, /* ide7 */ + {90, 6, 16, "ad"}, /* ide8 */ + {91, 6, 18, "ad"}, /* ide9 */ + + {8, 4, 0, "da"}, /* scsi disk0 */ + {65, 4, 16, "da"}, /* scsi disk1 */ + {66, 4, 32, "da"}, /* scsi disk2 */ + {67, 4, 48, "da"}, /* scsi disk3 */ + {68, 4, 64, "da"}, /* scsi disk4 */ + {69, 4, 80, "da"}, /* scsi disk5 */ + {70, 4, 96, "da"}, /* scsi disk6 */ + {71, 4, 112, "da"}, /* scsi disk7 */ + {128, 4, 128, "da"}, /* scsi disk8 */ + {129, 4, 144, "da"}, /* scsi disk9 */ + {130, 4, 160, "da"}, /* scsi disk10 */ + {131, 4, 176, "da"}, /* scsi disk11 */ + {132, 4, 192, "da"}, /* scsi disk12 */ + {133, 4, 208, "da"}, /* scsi disk13 */ + {134, 4, 224, "da"}, /* scsi disk14 */ + {135, 4, 240, "da"}, /* scsi disk15 */ + + {202, 4, 0, "xbd"}, /* xbd */ + + {0, 0, 0, NULL}, + }; + int major = vdevice >> 8; + int minor = vdevice & 0xff; + int i; + + if (vdevice & (1 << 28)) { + *unit = (vdevice & ((1 << 28) - 1)) >> 8; + *name = "xbd"; + } + + for (i = 0; info[i].major; i++) { + if (info[i].major == major) { + *unit = info[i].base + (minor >> info[i].shift); + *name = info[i].name; + return; + } + } + + *unit = minor >> 4; + *name = "xbd"; +} int -xlvbd_add(blkif_sector_t capacity, int unit, uint16_t vdisk_info, uint16_t sector_size, +xlvbd_add(blkif_sector_t capacity, int vdevice, uint16_t vdisk_info, uint16_t sector_size, struct blkfront_info *info) { struct xb_softc *sc; - int error = 0; - int unitno = unit - 767; + int unit, error = 0; + const char *name; + + blkfront_vdevice_to_unit(vdevice, &unit, &name); sc = (struct xb_softc *)malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO); - sc->xb_unit = unitno; + sc->xb_unit = unit; sc->xb_info = info; info->sc = sc; memset(&sc->xb_disk, 0, sizeof(sc->xb_disk)); sc->xb_disk = disk_alloc(); - sc->xb_disk->d_unit = unitno; + sc->xb_disk->d_unit = sc->xb_unit; sc->xb_disk->d_open = blkif_open; sc->xb_disk->d_close = blkif_close; sc->xb_disk->d_ioctl = blkif_ioctl; sc->xb_disk->d_strategy = xb_strategy; - sc->xb_disk->d_name = "xbd"; + sc->xb_disk->d_name = name; sc->xb_disk->d_drv1 = sc; sc->xb_disk->d_sectorsize = sector_size; @@ -332,6 +401,12 @@ static int talk_to_backend(struct xenbus message = "writing event-channel"; goto abort_transaction; } + err = xenbus_printf(xbt, dev->nodename, + "protocol", "%s", XEN_IO_PROTO_ABI_NATIVE); + if (err) { + message = "writing protocol"; + goto abort_transaction; + } err = xenbus_transaction_end(xbt, 0); if (err) { From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 17:17:55 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3844D1065673; Fri, 28 Nov 2008 17:17:55 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2A6138FC0A; Fri, 28 Nov 2008 17:17:55 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASHHtbI024995; Fri, 28 Nov 2008 17:17:55 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASHHt31024994; Fri, 28 Nov 2008 17:17:55 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811281717.mASHHt31024994@svn.freebsd.org> From: Doug Rabson Date: Fri, 28 Nov 2008 17:17:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185399 - user/dfr/xenhvm/6/sys/dev/xen/netfront X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 17:17:55 -0000 Author: dfr Date: Fri Nov 28 17:17:54 2008 New Revision: 185399 URL: http://svn.freebsd.org/changeset/base/185399 Log: Suppress debug printfs. Make this build on amd64 and set the IFF_MULTICAST flag which is required for IPv6. Modified: user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c Modified: user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c ============================================================================== --- user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c Fri Nov 28 17:00:19 2008 (r185398) +++ user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c Fri Nov 28 17:17:54 2008 (r185399) @@ -66,6 +66,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -327,9 +328,12 @@ xennet_get_rx_ref(struct netfront_info * printf("[XEN] " fmt, ##args) #define WPRINTK(fmt, args...) \ printf("[XEN] " fmt, ##args) +#if 0 #define DPRINTK(fmt, args...) \ printf("[XEN] " fmt, ##args) - +#else +#define DPRINTK(fmt, args...) +#endif static __inline struct mbuf* makembuf (struct mbuf *buf) @@ -395,8 +399,6 @@ netfront_probe(struct xenbus_device *dev struct ifnet *ifp; struct netfront_info *info; - printf("netfront_probe() \n"); - err = create_netdev(dev, &ifp); if (err) { xenbus_dev_fatal(dev, err, "creating netdev"); @@ -1215,7 +1217,7 @@ xennet_get_responses(struct netfront_inf MULTI_update_va_mapping(mcl, (u_long)vaddr, (((vm_paddr_t)mfn) << PAGE_SHIFT) | PG_RW | PG_V | PG_M | PG_A, 0); - pfn = (uint32_t)m->m_ext.ext_args; + pfn = (uintptr_t)m->m_ext.ext_args; mmu->ptr = ((vm_paddr_t)mfn << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE; mmu->val = pfn; @@ -1549,8 +1551,6 @@ network_connect(struct ifnet *ifp) netif_rx_request_t *req; u_int feature_rx_copy, feature_rx_flip; - printf("network_connect\n"); - np = ifp->if_softc; err = xenbus_scanf(XBT_NIL, np->xbdev->otherend, "feature-rx-copy", "%u", &feature_rx_copy); @@ -1704,7 +1704,7 @@ create_netdev(struct xenbus_device *dev, *ifpp = ifp = np->xn_ifp = if_alloc(IFT_ETHER); ifp->if_softc = np; if_initname(ifp, "xn", ifno++/* ifno */); - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = xn_ioctl; ifp->if_output = ether_output; ifp->if_start = xn_start; @@ -1831,7 +1831,7 @@ netif_init(void *unused) if (is_initial_xendomain()) return; - IPRINTK("Initialising virtual ethernet driver.\n"); + DPRINTK("Initialising virtual ethernet driver.\n"); xenbus_register_frontend(&netfront); } From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 20:47:48 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EB3AC1065670; Fri, 28 Nov 2008 20:47:48 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BE1078FC16; Fri, 28 Nov 2008 20:47:48 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mASKlmDQ029586; Fri, 28 Nov 2008 20:47:48 GMT (envelope-from peter@svn.freebsd.org) Received: (from peter@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mASKlmdV029585; Fri, 28 Nov 2008 20:47:48 GMT (envelope-from peter@svn.freebsd.org) Message-Id: <200811282047.mASKlmdV029585@svn.freebsd.org> From: Peter Wemm Date: Fri, 28 Nov 2008 20:47:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185413 - user/peter/kinfo X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2008 20:47:49 -0000 Author: peter Date: Fri Nov 28 20:47:48 2008 New Revision: 185413 URL: http://svn.freebsd.org/changeset/base/185413 Log: kinfo_file, kinfo_vmentry, etc WIP Added: user/peter/kinfo/ - copied from r185412, head/ From owner-svn-src-user@FreeBSD.ORG Sat Nov 29 12:08:41 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 644211065670; Sat, 29 Nov 2008 12:08:41 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 560A98FC14; Sat, 29 Nov 2008 12:08:41 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mATC8foB050466; Sat, 29 Nov 2008 12:08:41 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mATC8fbm050463; Sat, 29 Nov 2008 12:08:41 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811291208.mATC8fbm050463@svn.freebsd.org> From: Doug Rabson Date: Sat, 29 Nov 2008 12:08:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185429 - in user/dfr/xenhvm/6/sys: conf i386/xen xen X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Nov 2008 12:08:41 -0000 Author: dfr Date: Sat Nov 29 12:08:41 2008 New Revision: 185429 URL: http://svn.freebsd.org/changeset/base/185429 Log: Factor out the reboot handler so that I can use it in HVM mode. Change it to call shutdown_nice() instead of reboot() for consistency with e.g. the Ctrl-Alt-Del handler in syscons. Added: user/dfr/xenhvm/6/sys/xen/reboot.c (contents, props changed) - copied, changed from r185387, user/dfr/xenhvm/6/sys/i386/xen/xen_machdep.c Modified: user/dfr/xenhvm/6/sys/conf/files user/dfr/xenhvm/6/sys/i386/xen/xen_machdep.c Modified: user/dfr/xenhvm/6/sys/conf/files ============================================================================== --- user/dfr/xenhvm/6/sys/conf/files Sat Nov 29 08:45:20 2008 (r185428) +++ user/dfr/xenhvm/6/sys/conf/files Sat Nov 29 12:08:41 2008 (r185429) @@ -2051,6 +2051,7 @@ xen/gnttab.c optional xen/features.c optional xen xen/evtchn/evtchn.c optional xen xen/evtchn/evtchn_dev.c optional xen +xen/reboot.c optional xen xen/xenbus/xenbus_client.c optional xen xen/xenbus/xenbus_comms.c optional xen xen/xenbus/xenbus_dev.c optional xen @@ -2068,6 +2069,7 @@ xen/gnttab.c optional xen/features.c optional xenhvm dev/xen/xenpci/evtchn.c optional xenhvm xen/evtchn/evtchn_dev.c optional xenhvm +xen/reboot.c optional xenhvm xen/xenbus/xenbus_client.c optional xenhvm xen/xenbus/xenbus_comms.c optional xenhvm xen/xenbus/xenbus_dev.c optional xenhvm Modified: user/dfr/xenhvm/6/sys/i386/xen/xen_machdep.c ============================================================================== --- user/dfr/xenhvm/6/sys/i386/xen/xen_machdep.c Sat Nov 29 08:45:20 2008 (r185428) +++ user/dfr/xenhvm/6/sys/i386/xen/xen_machdep.c Sat Nov 29 12:08:41 2008 (r185429) @@ -1135,221 +1135,6 @@ trap_info_t trap_table[] = { { 0, 0, 0, 0 } }; - -static void -shutdown_handler(struct xenbus_watch *watch, - const char **vec, unsigned int len) -{ - char *str; - struct xenbus_transaction xbt; - int err, howto; - struct reboot_args uap; - - howto = 0; - - again: - err = xenbus_transaction_start(&xbt); - if (err) - return; - str = (char *)xenbus_read(xbt, "control", "shutdown", NULL); - /* Ignore read errors and empty reads. */ - if (XENBUS_IS_ERR_READ(str)) { - xenbus_transaction_end(xbt, 1); - return; - } - - xenbus_write(xbt, "control", "shutdown", ""); - - err = xenbus_transaction_end(xbt, 0); - if (err == EAGAIN) { - free(str, M_DEVBUF); - goto again; - } - - if (strcmp(str, "reboot") == 0) - howto = 0; - else if (strcmp(str, "poweroff") == 0) - howto |= (RB_POWEROFF | RB_HALT); - else if (strcmp(str, "halt") == 0) - howto |= RB_HALT; - else if (strcmp(str, "suspend") == 0) - howto = -1; - else { - printf("Ignoring shutdown request: %s\n", str); - goto done; - } -#ifdef notyet - if (howto == -1) { - do_suspend(NULL); - goto done; - } -#else - if (howto == -1) { - printf("suspend not currently supported\n"); - goto done; - } -#endif - uap.opt = howto; - reboot(curthread, &uap); - done: - free(str, M_DEVBUF); -} - -static struct xenbus_watch shutdown_watch = { - .node = "control/shutdown", - .callback = shutdown_handler -}; - - -void setup_shutdown_watcher(void *unused); - - -void -setup_shutdown_watcher(void *unused) -{ - if (register_xenbus_watch(&shutdown_watch)) - printf("Failed to set shutdown watcher\n"); -} - - -SYSINIT(shutdown, SI_SUB_RUN_SCHEDULER, SI_ORDER_ANY, setup_shutdown_watcher, NULL); - -#ifdef notyet - -static void -xen_suspend(void *ignore) -{ - int i, j, k, fpp; - - extern void time_resume(void); - extern unsigned long max_pfn; - extern unsigned long *pfn_to_mfn_frame_list_list; - extern unsigned long *pfn_to_mfn_frame_list[]; - -#ifdef CONFIG_SMP -#error "do_suspend must be run cpu 0 - need to create separate thread" - cpumask_t prev_online_cpus; - int vcpu_prepare(int vcpu); -#endif - - int err = 0; - - PANIC_IF(smp_processor_id() != 0); - -#if defined(CONFIG_SMP) && !defined(CONFIG_HOTPLUG_CPU) - if (num_online_cpus() > 1) { - printk(KERN_WARNING "Can't suspend SMP guests " - "without CONFIG_HOTPLUG_CPU\n"); - return -EOPNOTSUPP; - } -#endif - - xenbus_suspend(); - -#ifdef CONFIG_SMP - lock_cpu_hotplug(); - /* - * Take all other CPUs offline. We hold the hotplug semaphore to - * avoid other processes bringing up CPUs under our feet. - */ - cpus_clear(prev_online_cpus); - while (num_online_cpus() > 1) { - for_each_online_cpu(i) { - if (i == 0) - continue; - unlock_cpu_hotplug(); - err = cpu_down(i); - lock_cpu_hotplug(); - if (err != 0) { - printk(KERN_CRIT "Failed to take all CPUs " - "down: %d.\n", err); - goto out_reenable_cpus; - } - cpu_set(i, prev_online_cpus); - } - } -#endif /* CONFIG_SMP */ - - preempt_disable(); - - - __cli(); - preempt_enable(); -#ifdef SMP - unlock_cpu_hotplug(); -#endif - gnttab_suspend(); - - pmap_kremove(HYPERVISOR_shared_info); - - xen_start_info->store_mfn = mfn_to_pfn(xen_start_info->store_mfn); - xen_start_info->console.domU.mfn = mfn_to_pfn(xen_start_info->console.domU.mfn); - - /* - * We'll stop somewhere inside this hypercall. When it returns, - * we'll start resuming after the restore. - */ - HYPERVISOR_suspend(VTOMFN(xen_start_info)); - - pmap_kenter_ma(HYPERVISOR_shared_info, xen_start_info->shared_info); - set_fixmap(FIX_SHARED_INFO, xen_start_info->shared_info); - -#if 0 - memset(empty_zero_page, 0, PAGE_SIZE); -#endif - HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = - VTOMFN(pfn_to_mfn_frame_list_list); - - fpp = PAGE_SIZE/sizeof(unsigned long); - for (i = 0, j = 0, k = -1; i < max_pfn; i += fpp, j++) { - if ((j % fpp) == 0) { - k++; - pfn_to_mfn_frame_list_list[k] = - VTOMFN(pfn_to_mfn_frame_list[k]); - j = 0; - } - pfn_to_mfn_frame_list[k][j] = - VTOMFN(&phys_to_machine_mapping[i]); - } - HYPERVISOR_shared_info->arch.max_pfn = max_pfn; - - gnttab_resume(); - - irq_resume(); - - time_resume(); - - __sti(); - - xencons_resume(); - -#ifdef CONFIG_SMP - for_each_cpu(i) - vcpu_prepare(i); - -#endif - /* - * Only resume xenbus /after/ we've prepared our VCPUs; otherwise - * the VCPU hotplug callback can race with our vcpu_prepare - */ - xenbus_resume(); - -#ifdef CONFIG_SMP - out_reenable_cpus: - for_each_cpu_mask(i, prev_online_cpus) { - j = cpu_up(i); - if ((j != 0) && !cpu_online(i)) { - printk(KERN_CRIT "Failed to bring cpu " - "%d back up (%d).\n", - i, j); - err = j; - } - } -#endif - return err; -} - -#endif /* notyet */ /********** CODE WORTH KEEPING ABOVE HERE *****************/ void xen_failsafe_handler(void); Copied and modified: user/dfr/xenhvm/6/sys/xen/reboot.c (from r185387, user/dfr/xenhvm/6/sys/i386/xen/xen_machdep.c) ============================================================================== --- user/dfr/xenhvm/6/sys/i386/xen/xen_machdep.c Fri Nov 28 15:50:35 2008 (r185387, copy source) +++ user/dfr/xenhvm/6/sys/xen/reboot.c Sat Nov 29 12:08:41 2008 (r185429) @@ -35,1106 +35,12 @@ __FBSDID("$FreeBSD$"); #include #include -#include -#include #include #include #include -#include #include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - - -#include -#include -#include -#include #include -#include -#include -#include -#ifdef SMP -#include -#endif - - -#include - - -#define IDTVEC(name) __CONCAT(X,name) - -extern inthand_t -IDTVEC(div), IDTVEC(dbg), IDTVEC(nmi), IDTVEC(bpt), IDTVEC(ofl), - IDTVEC(bnd), IDTVEC(ill), IDTVEC(dna), IDTVEC(fpusegm), - IDTVEC(tss), IDTVEC(missing), IDTVEC(stk), IDTVEC(prot), - IDTVEC(page), IDTVEC(mchk), IDTVEC(rsvd), IDTVEC(fpu), IDTVEC(align), - IDTVEC(xmm), IDTVEC(lcall_syscall), IDTVEC(int0x80_syscall); - - -int xendebug_flags; -start_info_t *xen_start_info; -shared_info_t *HYPERVISOR_shared_info; -xen_pfn_t *xen_machine_phys = machine_to_phys_mapping; -xen_pfn_t *xen_phys_machine; -int preemptable, init_first; -extern unsigned int avail_space; - -void ni_cli(void); -void ni_sti(void); - - -void -ni_cli(void) -{ - __asm__("pushl %edx;" - "pushl %eax;" - ); - __cli(); - __asm__("popl %eax;" - "popl %edx;" - ); -} - - -void -ni_sti(void) -{ - __asm__("pushl %edx;" - "pushl %esi;" - "pushl %eax;" - ); - __sti(); - __asm__("popl %eax;" - "popl %esi;" - "popl %edx;" - ); -} - -/* - * Modify the cmd_line by converting ',' to NULLs so that it is in a format - * suitable for the static env vars. - */ -char * -xen_setbootenv(char *cmd_line) -{ - char *cmd_line_next; - - /* Skip leading spaces */ - for (; *cmd_line == ' '; cmd_line++); - - printk("xen_setbootenv(): cmd_line='%s'\n", cmd_line); - - for (cmd_line_next = cmd_line; strsep(&cmd_line_next, ",") != NULL;); - return cmd_line; -} - -static struct -{ - const char *ev; - int mask; -} howto_names[] = { - {"boot_askname", RB_ASKNAME}, - {"boot_single", RB_SINGLE}, - {"boot_nosync", RB_NOSYNC}, - {"boot_halt", RB_ASKNAME}, - {"boot_serial", RB_SERIAL}, - {"boot_cdrom", RB_CDROM}, - {"boot_gdb", RB_GDB}, - {"boot_gdb_pause", RB_RESERVED1}, - {"boot_verbose", RB_VERBOSE}, - {"boot_multicons", RB_MULTIPLE}, - {NULL, 0} -}; - -int -xen_boothowto(char *envp) -{ - int i, howto = 0; - - /* get equivalents from the environment */ - for (i = 0; howto_names[i].ev != NULL; i++) - if (getenv(howto_names[i].ev) != NULL) - howto |= howto_names[i].mask; - return howto; -} - -#define PRINTK_BUFSIZE 1024 -void -printk(const char *fmt, ...) -{ - __va_list ap; - int retval; - static char buf[PRINTK_BUFSIZE]; - - return; - - va_start(ap, fmt); - retval = vsnprintf(buf, PRINTK_BUFSIZE - 1, fmt, ap); - va_end(ap); - buf[retval] = 0; - (void)HYPERVISOR_console_write(buf, retval); -} - - -#define XPQUEUE_SIZE 128 - -struct mmu_log { - char *file; - int line; -}; - -#ifdef SMP -/* per-cpu queues and indices */ -#ifdef INVARIANTS -static struct mmu_log xpq_queue_log[MAX_VIRT_CPUS][XPQUEUE_SIZE]; -#endif - -static int xpq_idx[MAX_VIRT_CPUS]; -static mmu_update_t xpq_queue[MAX_VIRT_CPUS][XPQUEUE_SIZE]; - -#define XPQ_QUEUE xpq_queue[vcpu] -#define XPQ_IDX xpq_idx[vcpu] -#define SET_VCPU() int vcpu = smp_processor_id() - -#define XPQ_QUEUE_LOG xpq_queue_log[vcpu] -#else - -static mmu_update_t xpq_queue[XPQUEUE_SIZE]; -static struct mmu_log xpq_queue_log[XPQUEUE_SIZE]; -static int xpq_idx = 0; - -#define XPQ_QUEUE_LOG xpq_queue_log -#define XPQ_QUEUE xpq_queue -#define XPQ_IDX xpq_idx -#define SET_VCPU() -#endif /* !SMP */ - -#define XPQ_IDX_INC atomic_add_int(&XPQ_IDX, 1); - -#if 0 -static void -xen_dump_queue(void) -{ - int _xpq_idx = XPQ_IDX; - int i; - - if (_xpq_idx <= 1) - return; - - printk("xen_dump_queue(): %u entries\n", _xpq_idx); - for (i = 0; i < _xpq_idx; i++) { - printk(" val: %llx ptr: %llx\n", XPQ_QUEUE[i].val, XPQ_QUEUE[i].ptr); - } -} -#endif - - -static __inline void -_xen_flush_queue(void) -{ - SET_VCPU(); - int _xpq_idx = XPQ_IDX; - int error, i; - /* window of vulnerability here? */ - - if (__predict_true(gdtset)) - critical_enter(); - XPQ_IDX = 0; - /* Make sure index is cleared first to avoid double updates. */ - error = HYPERVISOR_mmu_update((mmu_update_t *)&XPQ_QUEUE, - _xpq_idx, NULL, DOMID_SELF); - -#if 0 - if (__predict_true(gdtset)) - for (i = _xpq_idx; i > 0;) { - if (i >= 3) { - CTR6(KTR_PMAP, "mmu:val: %lx ptr: %lx val: %lx " - "ptr: %lx val: %lx ptr: %lx", - (XPQ_QUEUE[i-1].val & 0xffffffff), - (XPQ_QUEUE[i-1].ptr & 0xffffffff), - (XPQ_QUEUE[i-2].val & 0xffffffff), - (XPQ_QUEUE[i-2].ptr & 0xffffffff), - (XPQ_QUEUE[i-3].val & 0xffffffff), - (XPQ_QUEUE[i-3].ptr & 0xffffffff)); - i -= 3; - } else if (i == 2) { - CTR4(KTR_PMAP, "mmu: val: %lx ptr: %lx val: %lx ptr: %lx", - (XPQ_QUEUE[i-1].val & 0xffffffff), - (XPQ_QUEUE[i-1].ptr & 0xffffffff), - (XPQ_QUEUE[i-2].val & 0xffffffff), - (XPQ_QUEUE[i-2].ptr & 0xffffffff)); - i = 0; - } else { - CTR2(KTR_PMAP, "mmu: val: %lx ptr: %lx", - (XPQ_QUEUE[i-1].val & 0xffffffff), - (XPQ_QUEUE[i-1].ptr & 0xffffffff)); - i = 0; - } - } -#endif - if (__predict_true(gdtset)) - critical_exit(); - if (__predict_false(error < 0)) { - for (i = 0; i < _xpq_idx; i++) - printf("val: %llx ptr: %llx\n", - XPQ_QUEUE[i].val, XPQ_QUEUE[i].ptr); - panic("Failed to execute MMU updates: %d", error); - } - -} - -void -xen_flush_queue(void) -{ - SET_VCPU(); - if (XPQ_IDX != 0) _xen_flush_queue(); -} - -static __inline void -xen_increment_idx(void) -{ - SET_VCPU(); - - XPQ_IDX++; - if (__predict_false(XPQ_IDX == XPQUEUE_SIZE)) - xen_flush_queue(); -} - -void -xen_check_queue(void) -{ -#ifdef INVARIANTS - SET_VCPU(); - - KASSERT(XPQ_IDX == 0, ("pending operations XPQ_IDX=%d", XPQ_IDX)); -#endif -} - -void -xen_invlpg(vm_offset_t va) -{ - struct mmuext_op op; - op.cmd = MMUEXT_INVLPG_ALL; - op.arg1.linear_addr = va & ~PAGE_MASK; - PANIC_IF(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0); -} - -void -xen_load_cr3(u_int val) -{ - struct mmuext_op op; -#ifdef INVARIANTS - SET_VCPU(); - - KASSERT(XPQ_IDX == 0, ("pending operations XPQ_IDX=%d", XPQ_IDX)); -#endif - op.cmd = MMUEXT_NEW_BASEPTR; - op.arg1.mfn = xpmap_ptom(val) >> PAGE_SHIFT; - PANIC_IF(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0); -} - -void -xen_restore_flags(u_int eflags) -{ - - if (eflags > 1) - eflags = ((eflags & PSL_I) == 0); - - __restore_flags(eflags); -} - -int -xen_save_and_cli(void) -{ - int eflags; - - __save_and_cli(eflags); - return (eflags); -} - -void -xen_cli(void) -{ - __cli(); -} - -void -xen_sti(void) -{ - __sti(); -} - -u_int -xen_rcr2(void) -{ - - return (HYPERVISOR_shared_info->vcpu_info[curcpu].arch.cr2); -} - -void -_xen_machphys_update(vm_paddr_t mfn, vm_paddr_t pfn, char *file, int line) -{ - SET_VCPU(); - - if (__predict_true(gdtset)) - critical_enter(); - XPQ_QUEUE[XPQ_IDX].ptr = (mfn << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE; - XPQ_QUEUE[XPQ_IDX].val = pfn; -#ifdef INVARIANTS - XPQ_QUEUE_LOG[XPQ_IDX].file = file; - XPQ_QUEUE_LOG[XPQ_IDX].line = line; -#endif - xen_increment_idx(); - if (__predict_true(gdtset)) - critical_exit(); -} - -void -_xen_queue_pt_update(vm_paddr_t ptr, vm_paddr_t val, char *file, int line) -{ - SET_VCPU(); - - if (__predict_true(gdtset)) - mtx_assert(&vm_page_queue_mtx, MA_OWNED); - - KASSERT((ptr & 7) == 0, ("misaligned update")); - - if (__predict_true(gdtset)) - critical_enter(); - - XPQ_QUEUE[XPQ_IDX].ptr = ((uint64_t)ptr) | MMU_NORMAL_PT_UPDATE; - XPQ_QUEUE[XPQ_IDX].val = (uint64_t)val; -#ifdef INVARIANTS - XPQ_QUEUE_LOG[XPQ_IDX].file = file; - XPQ_QUEUE_LOG[XPQ_IDX].line = line; -#endif - xen_increment_idx(); - if (__predict_true(gdtset)) - critical_exit(); -} - -void -xen_pgdpt_pin(vm_paddr_t ma) -{ - struct mmuext_op op; - op.cmd = MMUEXT_PIN_L3_TABLE; - op.arg1.mfn = ma >> PAGE_SHIFT; - xen_flush_queue(); - PANIC_IF(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0); -} - -void -xen_pgd_pin(vm_paddr_t ma) -{ - struct mmuext_op op; - op.cmd = MMUEXT_PIN_L2_TABLE; - op.arg1.mfn = ma >> PAGE_SHIFT; - xen_flush_queue(); - PANIC_IF(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0); -} - -void -xen_pgd_unpin(vm_paddr_t ma) -{ - struct mmuext_op op; - op.cmd = MMUEXT_UNPIN_TABLE; - op.arg1.mfn = ma >> PAGE_SHIFT; - xen_flush_queue(); - PANIC_IF(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0); -} - -void -xen_pt_pin(vm_paddr_t ma) -{ - struct mmuext_op op; - op.cmd = MMUEXT_PIN_L1_TABLE; - op.arg1.mfn = ma >> PAGE_SHIFT; - printk("xen_pt_pin(): mfn=%x\n", op.arg1.mfn); - xen_flush_queue(); - PANIC_IF(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0); -} - -void -xen_pt_unpin(vm_paddr_t ma) -{ - struct mmuext_op op; - op.cmd = MMUEXT_UNPIN_TABLE; - op.arg1.mfn = ma >> PAGE_SHIFT; - xen_flush_queue(); - PANIC_IF(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0); -} - -void -xen_set_ldt(vm_paddr_t ptr, unsigned long len) -{ - struct mmuext_op op; - op.cmd = MMUEXT_SET_LDT; - op.arg1.linear_addr = ptr; - op.arg2.nr_ents = len; - xen_flush_queue(); - PANIC_IF(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0); -} - -void xen_tlb_flush(void) -{ - struct mmuext_op op; - op.cmd = MMUEXT_TLB_FLUSH_LOCAL; - xen_flush_queue(); - PANIC_IF(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0); -} - -void -xen_update_descriptor(union descriptor *table, union descriptor *entry) -{ - vm_paddr_t pa; - pt_entry_t *ptp; - - ptp = vtopte((vm_offset_t)table); - pa = (*ptp & PG_FRAME) | ((vm_offset_t)table & PAGE_MASK); - if (HYPERVISOR_update_descriptor(pa, *(uint64_t *)entry)) - panic("HYPERVISOR_update_descriptor failed\n"); -} - - -#if 0 -/* - * Bitmap is indexed by page number. If bit is set, the page is part of a - * xen_create_contiguous_region() area of memory. - */ -unsigned long *contiguous_bitmap; - -static void -contiguous_bitmap_set(unsigned long first_page, unsigned long nr_pages) -{ - unsigned long start_off, end_off, curr_idx, end_idx; - - curr_idx = first_page / BITS_PER_LONG; - start_off = first_page & (BITS_PER_LONG-1); - end_idx = (first_page + nr_pages) / BITS_PER_LONG; - end_off = (first_page + nr_pages) & (BITS_PER_LONG-1); - - if (curr_idx == end_idx) { - contiguous_bitmap[curr_idx] |= - ((1UL<> PAGE_SHIFT; - mfn = PFNTOMFN(pfn); - PFNTOMFN(pfn) = INVALID_P2M_ENTRY; - PANIC_IF(HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation) != 1); - } - - - /* 2. Get a new contiguous memory extent. */ - reservation.extent_order = order; - /* xenlinux hardcodes this because of aacraid - maybe set to 0 if we're not - * running with a broxen driver XXXEN - */ - reservation.address_bits = 31; - if (HYPERVISOR_memory_op(XENMEM_increase_reservation, &reservation) != 1) - goto fail; - - /* 3. Map the new extent in place of old pages. */ - for (i = 0; i < (1 << order); i++) { - int pfn; - pfn = VM_PAGE_TO_PHYS(&pages[i]) >> PAGE_SHIFT; - xen_machphys_update(mfn+i, pfn); - PFNTOMFN(pfn) = mfn+i; - } - - xen_tlb_flush(); - -#if 0 - contiguous_bitmap_set(VM_PAGE_TO_PHYS(&pages[0]) >> PAGE_SHIFT, 1UL << order); -#endif - - balloon_unlock(flags); - - return 0; - - fail: - reservation.extent_order = 0; - reservation.address_bits = 0; - - for (i = 0; i < (1 << order); i++) { - int pfn; - pfn = VM_PAGE_TO_PHYS(&pages[i]) >> PAGE_SHIFT; - PANIC_IF(HYPERVISOR_memory_op( - XENMEM_increase_reservation, &reservation) != 1); - xen_machphys_update(mfn, pfn); - PFNTOMFN(pfn) = mfn; - } - - xen_tlb_flush(); - - balloon_unlock(flags); - - return ENOMEM; -} - -void -xen_destroy_contiguous_region(void *addr, int npages) -{ - unsigned long mfn, i, flags, order, pfn0; - struct xen_memory_reservation reservation = { - .nr_extents = 1, - .extent_order = 0, - .domid = DOMID_SELF - }; - set_xen_guest_handle(reservation.extent_start, &mfn); - - pfn0 = vtophys(addr) >> PAGE_SHIFT; -#if 0 - scrub_pages(vstart, 1 << order); -#endif - /* can currently only handle power of two allocation */ - PANIC_IF(ffs(npages) != fls(npages)); - - /* 0. determine order */ - order = (ffs(npages) == fls(npages)) ? fls(npages) - 1 : fls(npages); - - balloon_lock(flags); - -#if 0 - contiguous_bitmap_clear(vtophys(addr) >> PAGE_SHIFT, 1UL << order); -#endif - - /* 1. Zap current PTEs, giving away the underlying pages. */ - for (i = 0; i < (1 << order); i++) { - int pfn; - uint64_t new_val = 0; - pfn = vtomach((char *)addr + i*PAGE_SIZE) >> PAGE_SHIFT; - - PANIC_IF(HYPERVISOR_update_va_mapping((vm_offset_t)((char *)addr + (i * PAGE_SIZE)), new_val, 0)); - PFNTOMFN(pfn) = INVALID_P2M_ENTRY; - PANIC_IF(HYPERVISOR_memory_op( - XENMEM_decrease_reservation, &reservation) != 1); - } - - /* 2. Map new pages in place of old pages. */ - for (i = 0; i < (1 << order); i++) { - int pfn; - uint64_t new_val; - pfn = pfn0 + i; - PANIC_IF(HYPERVISOR_memory_op(XENMEM_increase_reservation, &reservation) != 1); - - new_val = mfn << PAGE_SHIFT; - PANIC_IF(HYPERVISOR_update_va_mapping((vm_offset_t)addr + (i * PAGE_SIZE), - new_val, PG_KERNEL)); - xen_machphys_update(mfn, pfn); - PFNTOMFN(pfn) = mfn; - } - - xen_tlb_flush(); - - balloon_unlock(flags); -} - -extern unsigned long cpu0prvpage; -extern unsigned long *SMPpt; -extern struct user *proc0uarea; -extern vm_offset_t proc0kstack; -extern int vm86paddr, vm86phystk; -char *bootmem_start, *bootmem_current, *bootmem_end; - -pteinfo_t *pteinfo_list; -void initvalues(start_info_t *startinfo); - -struct ringbuf_head *xen_store; /* XXX move me */ -char *console_page; - -void * -bootmem_alloc(unsigned int size) -{ - char *retptr; - - retptr = bootmem_current; - PANIC_IF(retptr + size > bootmem_end); - bootmem_current += size; - - return retptr; -} - -void -bootmem_free(void *ptr, unsigned int size) -{ - char *tptr; - - tptr = ptr; - PANIC_IF(tptr != bootmem_current - size || - bootmem_current - size < bootmem_start); - - bootmem_current -= size; -} - -#if 0 -static vm_paddr_t -xpmap_mtop2(vm_paddr_t mpa) -{ - return ((machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) - ) | (mpa & ~PG_FRAME); -} - -static pd_entry_t -xpmap_get_bootpde(vm_paddr_t va) -{ - - return ((pd_entry_t *)xen_start_info->pt_base)[va >> 22]; -} - -static pd_entry_t -xpmap_get_vbootpde(vm_paddr_t va) -{ - pd_entry_t pde; - - pde = xpmap_get_bootpde(va); - if ((pde & PG_V) == 0) - return (pde & ~PG_FRAME); - return (pde & ~PG_FRAME) | - (xpmap_mtop2(pde & PG_FRAME) + KERNBASE); -} - -static pt_entry_t 8* -xpmap_get_bootptep(vm_paddr_t va) -{ - pd_entry_t pde; - - pde = xpmap_get_vbootpde(va); - if ((pde & PG_V) == 0) - return (void *)-1; -#define PT_MASK 0x003ff000 /* page table address bits */ - return &(((pt_entry_t *)(pde & PG_FRAME))[(va & PT_MASK) >> PAGE_SHIFT]); -} - -static pt_entry_t -xpmap_get_bootpte(vm_paddr_t va) -{ - - return xpmap_get_bootptep(va)[0]; -} -#endif - - -#ifdef ADD_ISA_HOLE -static void -shift_phys_machine(unsigned long *phys_machine, int nr_pages) -{ - - unsigned long *tmp_page, *current_page, *next_page; - int i; - *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-user@FreeBSD.ORG Sat Nov 29 17:34:46 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B317D1065686; Sat, 29 Nov 2008 17:34:46 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A27458FC20; Sat, 29 Nov 2008 17:34:46 +0000 (UTC) (envelope-from dfr@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mATHYkhb057834; Sat, 29 Nov 2008 17:34:46 GMT (envelope-from dfr@svn.freebsd.org) Received: (from dfr@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mATHYkQK057833; Sat, 29 Nov 2008 17:34:46 GMT (envelope-from dfr@svn.freebsd.org) Message-Id: <200811291734.mATHYkQK057833@svn.freebsd.org> From: Doug Rabson Date: Sat, 29 Nov 2008 17:34:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185444 - user/dfr/xenhvm/6/sys/dev/xen/netfront X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Nov 2008 17:34:46 -0000 Author: dfr Date: Sat Nov 29 17:34:46 2008 New Revision: 185444 URL: http://svn.freebsd.org/changeset/base/185444 Log: Don't call ether_ioctl() with locks held. Loop in xn_rxeof() until the backend stops adding stuff to the ring otherwise we miss RX interrupts which kills performance. Modified: user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c Modified: user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c ============================================================================== --- user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c Sat Nov 29 17:33:38 2008 (r185443) +++ user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c Sat Nov 29 17:34:46 2008 (r185444) @@ -858,110 +858,112 @@ xn_rxeof(struct netfront_info *np) multicall_entry_t *mcl; struct mbuf *m; struct mbuf_head rxq, errq; - int err, pages_flipped = 0; + int err, pages_flipped = 0, work_to_do; - XN_RX_LOCK_ASSERT(np); - if (!netfront_carrier_ok(np)) - return; + do { + XN_RX_LOCK_ASSERT(np); + if (!netfront_carrier_ok(np)) + return; - mbufq_init(&errq); - mbufq_init(&rxq); + mbufq_init(&errq); + mbufq_init(&rxq); - ifp = np->xn_ifp; + ifp = np->xn_ifp; - rp = np->rx.sring->rsp_prod; - rmb(); /* Ensure we see queued responses up to 'rp'. */ + rp = np->rx.sring->rsp_prod; + rmb(); /* Ensure we see queued responses up to 'rp'. */ + + i = np->rx.rsp_cons; + while ((i != rp)) { + memcpy(rx, RING_GET_RESPONSE(&np->rx, i), sizeof(*rx)); + memset(extras, 0, sizeof(rinfo.extras)); - i = np->rx.rsp_cons; - while ((i != rp)) { - memcpy(rx, RING_GET_RESPONSE(&np->rx, i), sizeof(*rx)); - memset(extras, 0, sizeof(rinfo.extras)); - - m = NULL; - err = xennet_get_responses(np, &rinfo, rp, &m, - &pages_flipped); + m = NULL; + err = xennet_get_responses(np, &rinfo, rp, &m, + &pages_flipped); - if (unlikely(err)) { + if (unlikely(err)) { if (m) - mbufq_tail(&errq, m); - np->stats.rx_errors++; - i = np->rx.rsp_cons; - continue; - } + mbufq_tail(&errq, m); + np->stats.rx_errors++; + i = np->rx.rsp_cons; + continue; + } - m->m_pkthdr.rcvif = ifp; - if ( rx->flags & NETRXF_data_validated ) { - /* Tell the stack the checksums are okay */ - /* - * XXX this isn't necessarily the case - need to add - * check - */ + m->m_pkthdr.rcvif = ifp; + if ( rx->flags & NETRXF_data_validated ) { + /* Tell the stack the checksums are okay */ + /* + * XXX this isn't necessarily the case - need to add + * check + */ - m->m_pkthdr.csum_flags |= - (CSUM_IP_CHECKED | CSUM_IP_VALID | CSUM_DATA_VALID - | CSUM_PSEUDO_HDR); - m->m_pkthdr.csum_data = 0xffff; - } + m->m_pkthdr.csum_flags |= + (CSUM_IP_CHECKED | CSUM_IP_VALID | CSUM_DATA_VALID + | CSUM_PSEUDO_HDR); + m->m_pkthdr.csum_data = 0xffff; + } - np->stats.rx_packets++; - np->stats.rx_bytes += m->m_pkthdr.len; + np->stats.rx_packets++; + np->stats.rx_bytes += m->m_pkthdr.len; - mbufq_tail(&rxq, m); - np->rx.rsp_cons = ++i; - } + mbufq_tail(&rxq, m); + np->rx.rsp_cons = ++i; + } - if (pages_flipped) { - /* Some pages are no longer absent... */ + if (pages_flipped) { + /* Some pages are no longer absent... */ #ifdef notyet - balloon_update_driver_allowance(-pages_flipped); + balloon_update_driver_allowance(-pages_flipped); #endif - /* Do all the remapping work, and M->P updates, in one big - * hypercall. - */ - if (!!xen_feature(XENFEAT_auto_translated_physmap)) { - mcl = np->rx_mcl + pages_flipped; - mcl->op = __HYPERVISOR_mmu_update; - mcl->args[0] = (u_long)np->rx_mmu; - mcl->args[1] = pages_flipped; - mcl->args[2] = 0; - mcl->args[3] = DOMID_SELF; - (void)HYPERVISOR_multicall(np->rx_mcl, - pages_flipped + 1); + /* Do all the remapping work, and M->P updates, in one big + * hypercall. + */ + if (!!xen_feature(XENFEAT_auto_translated_physmap)) { + mcl = np->rx_mcl + pages_flipped; + mcl->op = __HYPERVISOR_mmu_update; + mcl->args[0] = (u_long)np->rx_mmu; + mcl->args[1] = pages_flipped; + mcl->args[2] = 0; + mcl->args[3] = DOMID_SELF; + (void)HYPERVISOR_multicall(np->rx_mcl, + pages_flipped + 1); + } } - } - while ((m = mbufq_dequeue(&errq))) - m_freem(m); - - /* - * Process all the mbufs after the remapping is complete. - * Break the mbuf chain first though. - */ - while ((m = mbufq_dequeue(&rxq)) != NULL) { - ifp->if_ipackets++; - - /* - * Do we really need to drop the rx lock? + while ((m = mbufq_dequeue(&errq))) + m_freem(m); + + /* + * Process all the mbufs after the remapping is complete. + * Break the mbuf chain first though. */ - XN_RX_UNLOCK(np); - /* Pass it up. */ - (*ifp->if_input)(ifp, m); - XN_RX_LOCK(np); - } + while ((m = mbufq_dequeue(&rxq)) != NULL) { + ifp->if_ipackets++; + + /* + * Do we really need to drop the rx lock? + */ + XN_RX_UNLOCK(np); + /* Pass it up. */ + (*ifp->if_input)(ifp, m); + XN_RX_LOCK(np); + } - np->rx.rsp_cons = i; + np->rx.rsp_cons = i; #if 0 - /* If we get a callback with very few responses, reduce fill target. */ - /* NB. Note exponential increase, linear decrease. */ - if (((np->rx.req_prod_pvt - np->rx.sring->rsp_prod) > - ((3*np->rx_target) / 4)) && (--np->rx_target < np->rx_min_target)) - np->rx_target = np->rx_min_target; + /* If we get a callback with very few responses, reduce fill target. */ + /* NB. Note exponential increase, linear decrease. */ + if (((np->rx.req_prod_pvt - np->rx.sring->rsp_prod) > + ((3*np->rx_target) / 4)) && (--np->rx_target < np->rx_min_target)) + np->rx_target = np->rx_min_target; #endif - network_alloc_rx_buffers(np); + network_alloc_rx_buffers(np); - np->rx.sring->rsp_event = i + 1; + RING_FINAL_CHECK_FOR_RESPONSES(&np->rx, work_to_do); + } while (work_to_do); } static void @@ -1440,9 +1442,11 @@ xn_ioctl(struct ifnet *ifp, u_long cmd, if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) xn_ifinit_locked(sc); arp_ifinit(ifp, ifa); - } else + XN_UNLOCK(sc); + } else { + XN_UNLOCK(sc); error = ether_ioctl(ifp, cmd, data); - XN_UNLOCK(sc); + } break; case SIOCSIFMTU: /* XXX can we alter the MTU on a VN ?*/ From owner-svn-src-user@FreeBSD.ORG Sat Nov 29 20:55:11 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DEB491065670; Sat, 29 Nov 2008 20:55:11 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D21D58FC08; Sat, 29 Nov 2008 20:55:11 +0000 (UTC) (envelope-from peter@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mATKtB6Q062196; Sat, 29 Nov 2008 20:55:11 GMT (envelope-from peter@svn.freebsd.org) Received: (from peter@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mATKtB08062193; Sat, 29 Nov 2008 20:55:11 GMT (envelope-from peter@svn.freebsd.org) Message-Id: <200811292055.mATKtB08062193@svn.freebsd.org> From: Peter Wemm Date: Sat, 29 Nov 2008 20:55:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185453 - in user/peter/kinfo/sys: kern sys X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Nov 2008 20:55:12 -0000 Author: peter Date: Sat Nov 29 20:55:11 2008 New Revision: 185453 URL: http://svn.freebsd.org/changeset/base/185453 Log: WIP kinfo_file/kinfo_vmmentry tweaks. The idea: 1) to get the 32 and 64 bit versions in sync so that no shims are needed, Valgrind in particular excercises this. and: 2) reduce the size of the copyout. On large processes this turns out to be a huge problem. Valgrind also suffers from this since it needs to do this in a context that can't malloc. I want to pack the records. 3) Add new types.. 'tell me about fd N' and 'tell me about addr N'. Modified: user/peter/kinfo/sys/kern/kern_descrip.c user/peter/kinfo/sys/kern/kern_proc.c user/peter/kinfo/sys/sys/user.h Modified: user/peter/kinfo/sys/kern/kern_descrip.c ============================================================================== --- user/peter/kinfo/sys/kern/kern_descrip.c Sat Nov 29 20:22:02 2008 (r185452) +++ user/peter/kinfo/sys/kern/kern_descrip.c Sat Nov 29 20:55:11 2008 (r185453) @@ -2509,6 +2509,10 @@ sysctl_kern_file(SYSCTL_HANDLER_ARGS) SYSCTL_PROC(_kern, KERN_FILE, file, CTLTYPE_OPAQUE|CTLFLAG_RD, 0, 0, sysctl_kern_file, "S,xfile", "Entire file table"); +#ifdef KINFO_FILE_SIZE +CTASSERT(sizeof(struct kinfo_file) == KINFO_FILE_SIZE); +#endif + static int export_vnode_for_sysctl(struct vnode *vp, int type, struct kinfo_file *kif, struct filedesc *fdp, struct sysctl_req *req) Modified: user/peter/kinfo/sys/kern/kern_proc.c ============================================================================== --- user/peter/kinfo/sys/kern/kern_proc.c Sat Nov 29 20:22:02 2008 (r185452) +++ user/peter/kinfo/sys/kern/kern_proc.c Sat Nov 29 20:55:11 2008 (r185453) @@ -1337,6 +1337,10 @@ sysctl_kern_proc_sv_name(SYSCTL_HANDLER_ return (sysctl_handle_string(oidp, sv_name, 0, req)); } +#ifdef KINFO_VMENTRY_SIZE +CTASSERT(sizeof(struct kinfo_vmentry) == KINFO_VMENTRY_SIZE); +#endif + static int sysctl_kern_proc_vmmap(SYSCTL_HANDLER_ARGS) { @@ -1461,9 +1465,9 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_AR kve->kve_shadow_count = 0; } - kve->kve_start = (void*)entry->start; - kve->kve_end = (void*)entry->end; - kve->kve_offset = (off_t)entry->offset; + kve->kve_start = entry->start; + kve->kve_end = entry->end; + kve->kve_offset = entry->offset; if (entry->protection & VM_PROT_READ) kve->kve_protection |= KVME_PROT_READ; Modified: user/peter/kinfo/sys/sys/user.h ============================================================================== --- user/peter/kinfo/sys/sys/user.h Sat Nov 29 20:22:02 2008 (r185452) +++ user/peter/kinfo/sys/sys/user.h Sat Nov 29 20:55:11 2008 (r185453) @@ -236,6 +236,9 @@ struct user { struct kinfo_proc u_kproc; /* eproc */ }; +/* When exporting paths via sysctl, give a short version */ +#define KPROC_PATH_MAX 256 + /* * The KERN_PROC_FILE sysctl allows a process to dump the file descriptor * array of another process. @@ -277,20 +280,25 @@ struct user { #define KF_FLAG_DIRECT 0x00000040 #define KF_FLAG_HASLOCK 0x00000080 +#if defined(__amd64__) || defined(__i386__) +#define KINFO_FILE_SIZE 560 +#endif + struct kinfo_file { int kf_structsize; /* Size of kinfo_file. */ int kf_type; /* Descriptor type. */ int kf_fd; /* Array index. */ int kf_ref_count; /* Reference count. */ int kf_flags; /* Flags. */ - off_t kf_offset; /* Seek location. */ + int _kf_pad0; /* Alignment */ + uint64_t kf_offset; /* Seek location. */ int kf_vnode_type; /* Vnode type. */ int kf_sock_domain; /* Socket domain. */ int kf_sock_type; /* Socket type. */ int kf_sock_protocol; /* Socket protocol. */ - char kf_path[PATH_MAX]; /* Path to file, if any. */ struct sockaddr_storage kf_sa_local; /* Socket address. */ struct sockaddr_storage kf_sa_peer; /* Peer address. */ + char kf_path[KPROC_PATH_MAX]; /* Path to file, if any. */ }; /* @@ -313,23 +321,26 @@ struct kinfo_file { #define KVME_FLAG_COW 0x00000001 #define KVME_FLAG_NEEDS_COPY 0x00000002 +#if defined(__amd64__) || defined(__i386__) +#define KINFO_VMENTRY_SIZE 384 +#endif + struct kinfo_vmentry { int kve_structsize; /* Size of kinfo_vmmapentry. */ int kve_type; /* Type of map entry. */ - void *kve_start; /* Starting pointer. */ - void *kve_end; /* Finishing pointer. */ + uint64_t kve_start; /* Starting address. */ + uint64_t kve_end; /* Finishing address. */ + uint64_t kve_offset; /* Mapping offset in object */ + uint64_t kve_fileid; /* inode number if vnode */ + uint32_t kve_fsid; /* dev_t of vnode location */ int kve_flags; /* Flags on map entry. */ int kve_resident; /* Number of resident pages. */ int kve_private_resident; /* Number of private pages. */ int kve_protection; /* Protection bitmask. */ int kve_ref_count; /* VM obj ref count. */ int kve_shadow_count; /* VM obj shadow count. */ - char kve_path[PATH_MAX]; /* Path to VM obj, if any. */ - void *_kve_pspare[8]; /* Space for more stuff. */ - off_t kve_offset; /* Mapping offset in object */ - uint64_t kve_fileid; /* inode number of vnode */ - dev_t kve_fsid; /* dev_t of vnode location */ - int _kve_ispare[3]; /* Space for more stuff. */ + int _kve_ispare[15]; /* Space for more stuff. */ + char kve_path[KPROC_PATH_MAX]; /* Path to VM obj, if any. */ }; /* @@ -343,12 +354,15 @@ struct kinfo_vmentry { #define KKST_STATE_SWAPPED 1 /* Stack swapped out. */ #define KKST_STATE_RUNNING 2 /* Stack ephemeral. */ +#if defined(__amd64__) || defined(__i386__) +#define KINFO_KSTACK_SIZE 1096 +#endif + struct kinfo_kstack { lwpid_t kkst_tid; /* ID of thread. */ int kkst_state; /* Validity of stack. */ char kkst_trace[KKST_MAXLEN]; /* String representing stack. */ - void *_kkst_pspare[8]; /* Space for more stuff. */ - int _kkst_ispare[8]; /* Space for more stuff. */ + int _kkst_ispare[16]; /* Space for more stuff. */ }; #endif From owner-svn-src-user@FreeBSD.ORG Sat Nov 29 22:56:44 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E48AB106567A for ; Sat, 29 Nov 2008 22:56:44 +0000 (UTC) (envelope-from mat.macy@gmail.com) Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.230]) by mx1.freebsd.org (Postfix) with ESMTP id BA8A78FC17 for ; Sat, 29 Nov 2008 22:56:44 +0000 (UTC) (envelope-from mat.macy@gmail.com) Received: by rv-out-0506.google.com with SMTP id b25so1819351rvf.43 for ; Sat, 29 Nov 2008 14:56:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=sIyjBJHOsPKB/kidb/m4j51zyzJuWO7S17g19perJiA=; b=AG7iDsz67R1knOlcYwrAG8kSdpK8ndr+GiTF8daz/iPEHNFL44b3SQfXo73S7HY5TQ MATa3x/9tZoJqbQgiLfdhf0zkA1K2KV/TTYEbxaoPzMgnnDZEAOcQjrBbJVIV37UzBrr qtho2dGvVcLqPXauQU/U3aokbJaP1LYQLhdj4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=QUZvDdMFbVjjQxX8ss9pq//Jwv+O4ZCCA2noRdd6U1m8EyNtonAO6acXnoaaz2mGQg AEiKFKy1RBcZtxOewGIrJ+VW60FeQVZOYHqLDMy5SXJ32lqcNzwTLb+b6gTAjH619N2F jGyF/PEyGgE7q82kwYxmcXnkdiFTps1zkWBF0= Received: by 10.141.115.16 with SMTP id s16mr4417555rvm.209.1227999404435; Sat, 29 Nov 2008 14:56:44 -0800 (PST) Received: by 10.141.142.3 with HTTP; Sat, 29 Nov 2008 14:56:44 -0800 (PST) Message-ID: <3c1674c90811291456i80dcc67ie7278ae61dd786ea@mail.gmail.com> Date: Sat, 29 Nov 2008 22:56:44 +0000 From: "Kip Macy" Sender: mat.macy@gmail.com To: "Doug Rabson" In-Reply-To: <200811291734.mATHYkQK057833@svn.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200811291734.mATHYkQK057833@svn.freebsd.org> X-Google-Sender-Auth: c125bb1c2027f8e6 Cc: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: Re: svn commit: r185444 - user/dfr/xenhvm/6/sys/dev/xen/netfront X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Nov 2008 22:56:45 -0000 Hi Doug, Please push any such fixes back in to HEAD. Thanks, Kip On Sat, Nov 29, 2008 at 5:34 PM, Doug Rabson wrote: > Author: dfr > Date: Sat Nov 29 17:34:46 2008 > New Revision: 185444 > URL: http://svn.freebsd.org/changeset/base/185444 > > Log: > Don't call ether_ioctl() with locks held. Loop in xn_rxeof() until the backend > stops adding stuff to the ring otherwise we miss RX interrupts which kills > performance. > > Modified: > user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c > > Modified: user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c > ============================================================================== > --- user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c Sat Nov 29 17:33:38 2008 (r185443) > +++ user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c Sat Nov 29 17:34:46 2008 (r185444) > @@ -858,110 +858,112 @@ xn_rxeof(struct netfront_info *np) > multicall_entry_t *mcl; > struct mbuf *m; > struct mbuf_head rxq, errq; > - int err, pages_flipped = 0; > + int err, pages_flipped = 0, work_to_do; > > - XN_RX_LOCK_ASSERT(np); > - if (!netfront_carrier_ok(np)) > - return; > + do { > + XN_RX_LOCK_ASSERT(np); > + if (!netfront_carrier_ok(np)) > + return; > > - mbufq_init(&errq); > - mbufq_init(&rxq); > + mbufq_init(&errq); > + mbufq_init(&rxq); > > - ifp = np->xn_ifp; > + ifp = np->xn_ifp; > > - rp = np->rx.sring->rsp_prod; > - rmb(); /* Ensure we see queued responses up to 'rp'. */ > + rp = np->rx.sring->rsp_prod; > + rmb(); /* Ensure we see queued responses up to 'rp'. */ > + > + i = np->rx.rsp_cons; > + while ((i != rp)) { > + memcpy(rx, RING_GET_RESPONSE(&np->rx, i), sizeof(*rx)); > + memset(extras, 0, sizeof(rinfo.extras)); > > - i = np->rx.rsp_cons; > - while ((i != rp)) { > - memcpy(rx, RING_GET_RESPONSE(&np->rx, i), sizeof(*rx)); > - memset(extras, 0, sizeof(rinfo.extras)); > - > - m = NULL; > - err = xennet_get_responses(np, &rinfo, rp, &m, > - &pages_flipped); > + m = NULL; > + err = xennet_get_responses(np, &rinfo, rp, &m, > + &pages_flipped); > > - if (unlikely(err)) { > + if (unlikely(err)) { > if (m) > - mbufq_tail(&errq, m); > - np->stats.rx_errors++; > - i = np->rx.rsp_cons; > - continue; > - } > + mbufq_tail(&errq, m); > + np->stats.rx_errors++; > + i = np->rx.rsp_cons; > + continue; > + } > > - m->m_pkthdr.rcvif = ifp; > - if ( rx->flags & NETRXF_data_validated ) { > - /* Tell the stack the checksums are okay */ > - /* > - * XXX this isn't necessarily the case - need to add > - * check > - */ > + m->m_pkthdr.rcvif = ifp; > + if ( rx->flags & NETRXF_data_validated ) { > + /* Tell the stack the checksums are okay */ > + /* > + * XXX this isn't necessarily the case - need to add > + * check > + */ > > - m->m_pkthdr.csum_flags |= > - (CSUM_IP_CHECKED | CSUM_IP_VALID | CSUM_DATA_VALID > - | CSUM_PSEUDO_HDR); > - m->m_pkthdr.csum_data = 0xffff; > - } > + m->m_pkthdr.csum_flags |= > + (CSUM_IP_CHECKED | CSUM_IP_VALID | CSUM_DATA_VALID > + | CSUM_PSEUDO_HDR); > + m->m_pkthdr.csum_data = 0xffff; > + } > > - np->stats.rx_packets++; > - np->stats.rx_bytes += m->m_pkthdr.len; > + np->stats.rx_packets++; > + np->stats.rx_bytes += m->m_pkthdr.len; > > - mbufq_tail(&rxq, m); > - np->rx.rsp_cons = ++i; > - } > + mbufq_tail(&rxq, m); > + np->rx.rsp_cons = ++i; > + } > > - if (pages_flipped) { > - /* Some pages are no longer absent... */ > + if (pages_flipped) { > + /* Some pages are no longer absent... */ > #ifdef notyet > - balloon_update_driver_allowance(-pages_flipped); > + balloon_update_driver_allowance(-pages_flipped); > #endif > - /* Do all the remapping work, and M->P updates, in one big > - * hypercall. > - */ > - if (!!xen_feature(XENFEAT_auto_translated_physmap)) { > - mcl = np->rx_mcl + pages_flipped; > - mcl->op = __HYPERVISOR_mmu_update; > - mcl->args[0] = (u_long)np->rx_mmu; > - mcl->args[1] = pages_flipped; > - mcl->args[2] = 0; > - mcl->args[3] = DOMID_SELF; > - (void)HYPERVISOR_multicall(np->rx_mcl, > - pages_flipped + 1); > + /* Do all the remapping work, and M->P updates, in one big > + * hypercall. > + */ > + if (!!xen_feature(XENFEAT_auto_translated_physmap)) { > + mcl = np->rx_mcl + pages_flipped; > + mcl->op = __HYPERVISOR_mmu_update; > + mcl->args[0] = (u_long)np->rx_mmu; > + mcl->args[1] = pages_flipped; > + mcl->args[2] = 0; > + mcl->args[3] = DOMID_SELF; > + (void)HYPERVISOR_multicall(np->rx_mcl, > + pages_flipped + 1); > + } > } > - } > > - while ((m = mbufq_dequeue(&errq))) > - m_freem(m); > - > - /* > - * Process all the mbufs after the remapping is complete. > - * Break the mbuf chain first though. > - */ > - while ((m = mbufq_dequeue(&rxq)) != NULL) { > - ifp->if_ipackets++; > - > - /* > - * Do we really need to drop the rx lock? > + while ((m = mbufq_dequeue(&errq))) > + m_freem(m); > + > + /* > + * Process all the mbufs after the remapping is complete. > + * Break the mbuf chain first though. > */ > - XN_RX_UNLOCK(np); > - /* Pass it up. */ > - (*ifp->if_input)(ifp, m); > - XN_RX_LOCK(np); > - } > + while ((m = mbufq_dequeue(&rxq)) != NULL) { > + ifp->if_ipackets++; > + > + /* > + * Do we really need to drop the rx lock? > + */ > + XN_RX_UNLOCK(np); > + /* Pass it up. */ > + (*ifp->if_input)(ifp, m); > + XN_RX_LOCK(np); > + } > > - np->rx.rsp_cons = i; > + np->rx.rsp_cons = i; > > #if 0 > - /* If we get a callback with very few responses, reduce fill target. */ > - /* NB. Note exponential increase, linear decrease. */ > - if (((np->rx.req_prod_pvt - np->rx.sring->rsp_prod) > > - ((3*np->rx_target) / 4)) && (--np->rx_target < np->rx_min_target)) > - np->rx_target = np->rx_min_target; > + /* If we get a callback with very few responses, reduce fill target. */ > + /* NB. Note exponential increase, linear decrease. */ > + if (((np->rx.req_prod_pvt - np->rx.sring->rsp_prod) > > + ((3*np->rx_target) / 4)) && (--np->rx_target < np->rx_min_target)) > + np->rx_target = np->rx_min_target; > #endif > > - network_alloc_rx_buffers(np); > + network_alloc_rx_buffers(np); > > - np->rx.sring->rsp_event = i + 1; > + RING_FINAL_CHECK_FOR_RESPONSES(&np->rx, work_to_do); > + } while (work_to_do); > } > > static void > @@ -1440,9 +1442,11 @@ xn_ioctl(struct ifnet *ifp, u_long cmd, > if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) > xn_ifinit_locked(sc); > arp_ifinit(ifp, ifa); > - } else > + XN_UNLOCK(sc); > + } else { > + XN_UNLOCK(sc); > error = ether_ioctl(ifp, cmd, data); > - XN_UNLOCK(sc); > + } > break; > case SIOCSIFMTU: > /* XXX can we alter the MTU on a VN ?*/ > -- If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis