From owner-freebsd-hackers@freebsd.org Sat Jan 4 21:29:17 2020 Return-Path: Delivered-To: freebsd-hackers@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 0A4F91D4FAC for ; Sat, 4 Jan 2020 21:29:17 +0000 (UTC) (envelope-from crees@freebsd.org) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 47qvzc6TTCz4fJN for ; Sat, 4 Jan 2020 21:29:16 +0000 (UTC) (envelope-from crees@freebsd.org) Received: by mailman.nyi.freebsd.org (Postfix) id DE4BA1D4FAB; Sat, 4 Jan 2020 21:29:16 +0000 (UTC) Delivered-To: hackers@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 DE10C1D4FAA for ; Sat, 4 Jan 2020 21:29:16 +0000 (UTC) (envelope-from crees@freebsd.org) Received: from mail118c50.megamailservers.eu (mail1420c50.megamailservers.eu [91.136.14.20]) (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 47qvzc2ClYz4fJM; Sat, 4 Jan 2020 21:29:15 +0000 (UTC) (envelope-from crees@freebsd.org) X-Authenticated-User: crees@uwclub.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1578173353; bh=J6v0x+UNw2tucTKMENXcF04FZ0SejcNOKRHOiAN67/c=; h=Subject:From:To:References:Date:In-Reply-To:From; b=b0ca2z6L6KSB/utXcRSRIeewDFSNXbUfJn3hx40SeEgOTpswNlXr9rEODk2VBnzYm 28Jegx/EGCpt/wFJbuQiFNodcU1eFQNS+2M33FWZbpU4+bFAdYH7Vf0SYs1R6FB1AX 6yUn7jID6DU4LOETtkMwiGdogoXj6W5FRW/cfrS4= Feedback-ID: crees@freebsd.o Received: from pegasus.bayofrum.net (host-92-16-36-61.as13285.net [92.16.36.61]) (authenticated bits=0) by mail118c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 004LTCNs005476; Sat, 4 Jan 2020 21:29:13 +0000 Received: from [192.168.1.149] (unknown [192.168.1.149]) by pegasus.bayofrum.net (Postfix) with ESMTPSA id CF6D6B3FE; Sat, 4 Jan 2020 21:29:10 +0000 (GMT) Subject: Re: Fixing audio/oss to use callout instead of timeouts From: Chris Rees To: Chris Rees , hackers@FreeBSD.org References: <33a74368-73a7-fdc0-4655-cfce88d865e6@FreeBSD.org> Message-ID: <39ea5ba8-00d6-c5b2-4719-fba23bb53856@bayofrum.net> Date: Sat, 4 Jan 2020 21:29:10 +0000 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-bayofrum-MailScanner-Information: Please contact the ISP for more information X-bayofrum-MailScanner-ID: CF6D6B3FE.AC373 X-bayofrum-MailScanner: Found to be clean X-bayofrum-MailScanner-From: crees@freebsd.org X-Spam-Status: No X-CTCH-RefID: str=0001.0A0B0214.5E1103A9.003A, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Rules: X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=dLXYZ9Rb c=1 sm=1 tr=0 a=ExehvxHEHCe6C2o3spqpZQ==:117 a=ExehvxHEHCe6C2o3spqpZQ==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=IkcTkHD0fZMA:10 a=Jdjhy38mL1oA:10 a=ZB5LerlCAAAA:8 a=46YcauF8XkfZqN-N9H4A:9 a=QEXdDO2ut3YA:10 a=YKPTzOroS2oaEK2QgPcx:22 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 X-Rspamd-Queue-Id: 47qvzc2ClYz4fJM X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-1.94 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-0.95)[-0.953,0]; NEURAL_HAM_LONG(-0.98)[-0.985,0]; ASN(0.00)[asn:9115, ipnet:91.136.0.0/17, country:GB] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Jan 2020 21:29:17 -0000 [Keeping -hackers CC'd as again I've failed with from address :/] On 2020-01-04 21:27, Chris Rees wrote: > Hi John, > > On 2020-01-04 13:39, John Baldwin wrote: >> On 1/2/20 3:47 PM, Chris Rees wrote: >>> Hi Hackers (and perhaps John, as the author of r355732, sorry for >>> the duplicate), >>> >>> I've attempted to use the callout functions instead of the now >>> removed timeout functions for audio/oss, and I *think* that the code >>> already stores and retrieves the list of handlers, so it should be a >>> simple swap out. >>> >>> I've made this modification and run the module with mpg123 for a >>> while and it hasn't killed my laptop, but I'd just like to check >>> that I have the principle correct and haven't missed anything obvious. >>> >>> Please would you let me know if there is anything else I should have >>> done? >>> >>> https://www.bayofrum.net/cgi-bin/fossil/oss/vinfo/ad269d7cbc02bf38?diff=2 >>> >>> >>> (This is the change I've made to kernel/OS/FreeBSD/os_freebsd.c in oss) >>> >>> https://www.bayofrum.net/cgi-bin/fossil/oss/vinfo/ad269d7cbc02bf38?diff=2&dc=9999 >>> >> A few suggestions: >> >> 1) You should do the callout_init() during a SYSINIT or MOD_LOAD >> event to initialize >>     all the timers at once instead of doing it in oss_timeout(). >> >> 2) You should then add a SYSUNINIT or MOD_UNLOAD that uses >> callout_drain(). >> >> 3) You should add a mutex to protect the tmouts array and >> timeout_random, etc. >>     and use callout_init_mtx with that lock, but probably use >> CALLOUT_RETURNUNLOCKED >>     and drop the mutex right before calling the function (you can >> store the function >>     pointer and void * argument in local variables before dropping >> the lock to >>     be safe. >> >> 4) If possible, you should really alter the oss API so that drivers >> don't use >>     a timeout()-like interface, but instead use a callout directly >> (or an interface >>     that wraps callout).  This would let drivers take advantage of >> callout_init_mtx >>     with their own locks, etc. >> >> Does audio/oss contain all the code that makes use of oss_timeout? >> > Thanks so much for your feedback!  You've probably seen from the naive > change my level of kernel hacking. > > 1-2, I think I've done here: > > https://www.bayofrum.net/cgi-bin/fossil/oss/vdiff?from=ae2a86&to=b4376737b9d4a127 > > > (full context: > https://www.bayofrum.net/cgi-bin/fossil/oss/vdiff?from=ae2a86&to=b4376737b9d4a127&dc=9999) > > 3. The function pointer is constant, and the argument is a local > variable I think. > > 4. I agree, but I think it'd kill portability, and to be honest, the > only reason I even use OSS is just for my CMI8788 soundcard. If I've > managed this, I'm looking at porting the driver to FreeBSD's native > sound driver.  I don't think anyone uses OSS for any other reason. > > (5.) Yes, it doesn't appear elsewhere. > > Have I correctly understood you? > > Chris > > -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.