From owner-svn-src-head@freebsd.org Mon Aug 19 22:57:04 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6C5EFD432F; Mon, 19 Aug 2019 22:57:04 +0000 (UTC) (envelope-from cem@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 46C8Sc23dMz4XKD; Mon, 19 Aug 2019 22:57:04 +0000 (UTC) (envelope-from cem@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 23E9021C40; Mon, 19 Aug 2019 22:57:04 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x7JMv3cH089194; Mon, 19 Aug 2019 22:57:03 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x7JMv3UN089192; Mon, 19 Aug 2019 22:57:03 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201908192257.x7JMv3UN089192@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Mon, 19 Aug 2019 22:57:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351238 - head/sys/gdb X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/sys/gdb X-SVN-Commit-Revision: 351238 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Mon, 19 Aug 2019 22:57:04 -0000 Author: cem Date: Mon Aug 19 22:57:03 2019 New Revision: 351238 URL: https://svnweb.freebsd.org/changeset/base/351238 Log: gdb(4): Pack 'info threads' responses into fewer packets We suffer at least one round trip ACK latency every command / packet that GDB has to send and receive, and the response format for 'info threads' supports packing many threads IDs into a single packet, so do so. Adds and uses a new API, gdb_txbuf_has_capacity(), which checks for a certain number of bytes available in the outgoing txbuf. On an example amd64 VM, the number of RTTs to transmit this list is reduced by a factor of 110x. This is especially beneficial with recent GDB, which seems to request the list at least twice during attach. Modified: head/sys/gdb/gdb_int.h head/sys/gdb/gdb_main.c head/sys/gdb/gdb_packet.c Modified: head/sys/gdb/gdb_int.h ============================================================================== --- head/sys/gdb/gdb_int.h Mon Aug 19 22:53:05 2019 (r351237) +++ head/sys/gdb/gdb_int.h Mon Aug 19 22:57:03 2019 (r351238) @@ -62,6 +62,7 @@ void gdb_tx_begin(char); int gdb_tx_end(void); int gdb_tx_mem(const unsigned char *, size_t); void gdb_tx_reg(int); +bool gdb_txbuf_has_capacity(size_t); int gdb_rx_bindata(unsigned char *data, size_t datalen, size_t *amt); int gdb_search_mem(const unsigned char *addr, size_t size, const unsigned char *pat, size_t patlen, const unsigned char **found); Modified: head/sys/gdb/gdb_main.c ============================================================================== --- head/sys/gdb/gdb_main.c Mon Aug 19 22:53:05 2019 (r351237) +++ head/sys/gdb/gdb_main.c Mon Aug 19 22:57:03 2019 (r351238) @@ -123,6 +123,45 @@ gdb_do_mem_search(void) gdb_tx_err(EIO); } +static void +gdb_do_threadinfo(struct thread **thr_iter) +{ + static struct thread * const done_sentinel = (void *)(uintptr_t)1; + static const size_t tidsz_hex = sizeof(lwpid_t) * 2; + size_t tds_sent; + + if (*thr_iter == NULL) { + gdb_tx_err(ENXIO); + return; + } + + if (*thr_iter == done_sentinel) { + gdb_tx_begin('l'); + *thr_iter = NULL; + goto sendit; + } + + gdb_tx_begin('m'); + + for (tds_sent = 0; + *thr_iter != NULL && gdb_txbuf_has_capacity(tidsz_hex + 1); + *thr_iter = kdb_thr_next(*thr_iter), tds_sent++) { + if (tds_sent > 0) + gdb_tx_char(','); + gdb_tx_varhex((*thr_iter)->td_tid); + } + + /* + * Can't send EOF and "some" in same packet, so set a sentinel to send + * EOF when GDB asks us next. + */ + if (*thr_iter == NULL && tds_sent > 0) + *thr_iter = done_sentinel; + +sendit: + gdb_tx_end(); +} + static int gdb_trap(int type, int code) { @@ -268,23 +307,9 @@ gdb_trap(int type, int code) case 'q': /* General query. */ if (gdb_rx_equal("fThreadInfo")) { thr_iter = kdb_thr_first(); - gdb_tx_begin('m'); - gdb_tx_hex((long)thr_iter->td_tid, 8); - gdb_tx_end(); + gdb_do_threadinfo(&thr_iter); } else if (gdb_rx_equal("sThreadInfo")) { - if (thr_iter == NULL) { - gdb_tx_err(ENXIO); - break; - } - thr_iter = kdb_thr_next(thr_iter); - if (thr_iter != NULL) { - gdb_tx_begin('m'); - gdb_tx_hex((long)thr_iter->td_tid, 8); - gdb_tx_end(); - } else { - gdb_tx_begin('l'); - gdb_tx_end(); - } + gdb_do_threadinfo(&thr_iter); } else if (gdb_rx_equal("Search:memory:")) { gdb_do_mem_search(); } else if (!gdb_cpu_query()) Modified: head/sys/gdb/gdb_packet.c ============================================================================== --- head/sys/gdb/gdb_packet.c Mon Aug 19 22:53:05 2019 (r351237) +++ head/sys/gdb/gdb_packet.c Mon Aug 19 22:57:03 2019 (r351238) @@ -327,6 +327,12 @@ gdb_tx_reg(int regnum) gdb_tx_mem(regp, regsz); } +bool +gdb_txbuf_has_capacity(size_t req) +{ + return (((char *)gdb_txbuf + sizeof(gdb_txbuf) - gdb_txp) >= req); +} + /* Read binary data up until the end of the packet or until we have datalen decoded bytes */ int gdb_rx_bindata(unsigned char *data, size_t datalen, size_t *amt)