From owner-svn-src-head@freebsd.org Wed Jun 12 16:06:32 2019 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 66F0715BAFE8; Wed, 12 Jun 2019 16:06:32 +0000 (UTC) (envelope-from jtl@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0E6EA83833; Wed, 12 Jun 2019 16:06:32 +0000 (UTC) (envelope-from jtl@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DD3241B4D8; Wed, 12 Jun 2019 16:06:31 +0000 (UTC) (envelope-from jtl@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x5CG6VOd022583; Wed, 12 Jun 2019 16:06:31 GMT (envelope-from jtl@FreeBSD.org) Received: (from jtl@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x5CG6VjG022582; Wed, 12 Jun 2019 16:06:31 GMT (envelope-from jtl@FreeBSD.org) Message-Id: <201906121606.x5CG6VjG022582@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jtl set sender to jtl@FreeBSD.org using -f From: "Jonathan T. Looney" Date: Wed, 12 Jun 2019 16:06:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r348996 - head/sys/dev/ipmi X-SVN-Group: head X-SVN-Commit-Author: jtl X-SVN-Commit-Paths: head/sys/dev/ipmi X-SVN-Commit-Revision: 348996 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 0E6EA83833 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.93 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.93)[-0.934,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Jun 2019 16:06:32 -0000 Author: jtl Date: Wed Jun 12 16:06:31 2019 New Revision: 348996 URL: https://svnweb.freebsd.org/changeset/base/348996 Log: The current IPMI KCS code is waiting 100us for all transitions (roughly between each byte either sent or received). However, most transitions actually complete in 2-3 microseconds. By polling the status register with a delay of 4us with exponential backoff, the performance of most IPMI operations is significantly improved: - A BMC update on a Supermicro x9 or x11 motherboard goes from ~1 hour to ~6-8 minutes. - An ipmitool sensor list time improves by a factor of 4. Testing showed no significant improvements on a modern server by using a lower delay. The changes should also generally reduce the total amount of CPU or I/O bandwidth used for a given IPMI operation. Submitted by: Loic Prylli Reviewed by: jhb MFC after: 2 weeks Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D20527 Modified: head/sys/dev/ipmi/ipmi_kcs.c Modified: head/sys/dev/ipmi/ipmi_kcs.c ============================================================================== --- head/sys/dev/ipmi/ipmi_kcs.c Wed Jun 12 16:05:20 2019 (r348995) +++ head/sys/dev/ipmi/ipmi_kcs.c Wed Jun 12 16:06:31 2019 (r348996) @@ -48,55 +48,46 @@ __FBSDID("$FreeBSD$"); #include #endif +#define POLLING_DELAY_MIN 4 /* Waits are 2-3 usecs on typical systems */ +#define POLLING_DELAY_MAX 256 + static void kcs_clear_obf(struct ipmi_softc *, int); static void kcs_error(struct ipmi_softc *); -static int kcs_wait_for_ibf(struct ipmi_softc *, int); -static int kcs_wait_for_obf(struct ipmi_softc *, int); +static int kcs_wait_for_ibf(struct ipmi_softc *, bool); +static int kcs_wait_for_obf(struct ipmi_softc *, bool); static int -kcs_wait_for_ibf(struct ipmi_softc *sc, int state) +kcs_wait(struct ipmi_softc *sc, int value, int mask) { int status, start = ticks; + int delay_usec = POLLING_DELAY_MIN; status = INB(sc, KCS_CTL_STS); - if (state == 0) { - /* WAIT FOR IBF = 0 */ - while (ticks - start < MAX_TIMEOUT && status & KCS_STATUS_IBF) { - DELAY(100); - status = INB(sc, KCS_CTL_STS); - } - } else { - /* WAIT FOR IBF = 1 */ - while (ticks - start < MAX_TIMEOUT && - !(status & KCS_STATUS_IBF)) { - DELAY(100); - status = INB(sc, KCS_CTL_STS); - } + while (ticks - start < MAX_TIMEOUT && (status & mask) != value) { + /* + * The wait delay is increased exponentially to avoid putting + * significant load on I/O bus. + */ + DELAY(delay_usec); + status = INB(sc, KCS_CTL_STS); + if (delay_usec < POLLING_DELAY_MAX) + delay_usec *= 2; } return (status); } static int -kcs_wait_for_obf(struct ipmi_softc *sc, int state) +kcs_wait_for_ibf(struct ipmi_softc *sc, bool level) { - int status, start = ticks; - status = INB(sc, KCS_CTL_STS); - if (state == 0) { - /* WAIT FOR OBF = 0 */ - while (ticks - start < MAX_TIMEOUT && status & KCS_STATUS_OBF) { - DELAY(100); - status = INB(sc, KCS_CTL_STS); - } - } else { - /* WAIT FOR OBF = 1 */ - while (ticks - start < MAX_TIMEOUT && - !(status & KCS_STATUS_OBF)) { - DELAY(100); - status = INB(sc, KCS_CTL_STS); - } - } - return (status); + return (kcs_wait(sc, level ? KCS_STATUS_IBF : 0, KCS_STATUS_IBF)); +} + +static int +kcs_wait_for_obf(struct ipmi_softc *sc, bool level) +{ + + return (kcs_wait(sc, level ? KCS_STATUS_OBF : 0, KCS_STATUS_OBF)); } static void