From owner-svn-src-all@FreeBSD.ORG Wed May 7 06:22:51 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A0F2F9D; Wed, 7 May 2014 06:22:51 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8D7A198E; Wed, 7 May 2014 06:22:51 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s476MpTb087211; Wed, 7 May 2014 06:22:51 GMT (envelope-from trasz@svn.freebsd.org) Received: (from trasz@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s476MpJk087210; Wed, 7 May 2014 06:22:51 GMT (envelope-from trasz@svn.freebsd.org) Message-Id: <201405070622.s476MpJk087210@svn.freebsd.org> From: Edward Tomasz Napierala Date: Wed, 7 May 2014 06:22:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r265492 - stable/10/sys/cam/ctl X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 May 2014 06:22:51 -0000 Author: trasz Date: Wed May 7 06:22:51 2014 New Revision: 265492 URL: http://svnweb.freebsd.org/changeset/base/265492 Log: MFC r263978: Make it possible to have multiple CTL worker threads. Leave the default of 1 for now. Sponsored by: The FreeBSD Foundation Modified: stable/10/sys/cam/ctl/ctl.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/ctl/ctl.c ============================================================================== --- stable/10/sys/cam/ctl/ctl.c Wed May 7 06:20:35 2014 (r265491) +++ stable/10/sys/cam/ctl/ctl.c Wed May 7 06:22:51 2014 (r265492) @@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -320,6 +321,10 @@ static int ctl_is_single = 1; static int index_to_aps_page; SYSCTL_NODE(_kern_cam, OID_AUTO, ctl, CTLFLAG_RD, 0, "CAM Target Layer"); +static int worker_threads = 1; +TUNABLE_INT("kern.cam.ctl.worker_threads", &worker_threads); +SYSCTL_INT(_kern_cam_ctl, OID_AUTO, worker_threads, CTLFLAG_RDTUN, + &worker_threads, 1, "Number of worker threads"); /* * Serial number (0x80), device id (0x83), and supported pages (0x00) @@ -950,10 +955,7 @@ ctl_init(void) struct ctl_frontend *fe; struct ctl_lun *lun; uint8_t sc_id =0; -#if 0 - int i; -#endif - int error, retval; + int i, error, retval; //int isc_retval; retval = 0; @@ -1085,17 +1087,35 @@ ctl_init(void) mtx_unlock(&softc->ctl_lock); #endif - error = kproc_create(ctl_work_thread, softc, &softc->work_thread, 0, 0, - "ctl_thrd"); - if (error != 0) { - printf("error creating CTL work thread!\n"); - mtx_lock(&softc->ctl_lock); - ctl_free_lun(lun); - mtx_unlock(&softc->ctl_lock); - ctl_pool_free(internal_pool); - ctl_pool_free(emergency_pool); - ctl_pool_free(other_pool); - return (error); + if (worker_threads > MAXCPU || worker_threads == 0) { + printf("invalid kern.cam.ctl.worker_threads value; " + "setting to 1"); + worker_threads = 1; + } else if (worker_threads < 0) { + if (mp_ncpus > 2) { + /* + * Using more than two worker threads actually hurts + * performance due to lock contention. + */ + worker_threads = 2; + } else { + worker_threads = 1; + } + } + + for (i = 0; i < worker_threads; i++) { + error = kproc_create(ctl_work_thread, softc, &softc->work_thread, 0, 0, + "ctl_thrd%d", i); + if (error != 0) { + printf("error creating CTL work thread!\n"); + mtx_lock(&softc->ctl_lock); + ctl_free_lun(lun); + mtx_unlock(&softc->ctl_lock); + ctl_pool_free(internal_pool); + ctl_pool_free(emergency_pool); + ctl_pool_free(other_pool); + return (error); + } } if (bootverbose) printf("ctl: CAM Target Layer loaded\n"); @@ -12993,7 +13013,11 @@ ctl_work_thread(void *arg) if (io != NULL) { STAILQ_REMOVE_HEAD(&softc->rtr_queue, links); mtx_unlock(&softc->ctl_lock); - goto execute; + retval = ctl_scsiio(&io->scsiio); + if (retval != CTL_RETVAL_COMPLETE) + CTL_DEBUG_PRINT(("ctl_scsiio failed\n")); + mtx_lock(&softc->ctl_lock); + continue; } } io = (union ctl_io *)STAILQ_FIRST(&softc->incoming_queue); @@ -13024,19 +13048,6 @@ ctl_work_thread(void *arg) /* Back to the top of the loop to see what woke us up. */ continue; - -execute: - retval = ctl_scsiio(&io->scsiio); - switch (retval) { - case CTL_RETVAL_COMPLETE: - break; - default: - /* - * Probably need to make sure this doesn't happen. - */ - break; - } - mtx_lock(&softc->ctl_lock); } }