From nobody Sat Oct 05 12:01:23 2024 X-Original-To: freebsd-stable@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XLPCP2vxyz5YD0h for ; Sat, 05 Oct 2024 12:01:37 +0000 (UTC) (envelope-from haramrae@gmail.com) Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XLPCN5fStz4tdn; Sat, 5 Oct 2024 12:01:36 +0000 (UTC) (envelope-from haramrae@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20230601 header.b=BCO53Xo3; spf=pass (mx1.freebsd.org: domain of haramrae@gmail.com designates 2a00:1450:4864:20::629 as permitted sender) smtp.mailfrom=haramrae@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a99409f1cc7so620766b.2; Sat, 05 Oct 2024 05:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728129695; x=1728734495; darn=freebsd.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=B+ZA9Fgv7L9X4/nWwkjq33og8YI8jf6TY0F+zWZX22E=; b=BCO53Xo36/wSNYSYuOjSBIAR8xGfmH0NneKYEDE9NVL6Ji96ILde+3HdRSoQsEG4rW F8Yb0MVD+4xwUjmvDBOvwE7zaZpp66r7cm4md+TBLE4XzcilX4o7j+hZQFGn2CbXlfk1 Wl/ZWLZojL2PAdL6KZQ7/Db4O2PfF3qbwPYAfjze1YqQGe/Rs8suTIO9JOk+fUlogJAv UDiJ6QBoJhoE2KOiGx+FwJmpAUgcVXXc7mDJPMeu/adU2aYC9XEoKqK9LS817l1+54pJ wh/nNJEFaSSY5Lrs3Gq7frhT4Bam+FKmpXd/yL+MELtni5NnTuCIrICWapBiPUFpHLWz hQzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728129695; x=1728734495; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B+ZA9Fgv7L9X4/nWwkjq33og8YI8jf6TY0F+zWZX22E=; b=pE9GzY5vA4uwMbYUNNbwlZP5Mpc1Hn8ZMc71FfOcIMSXyk//8YsUFNhMJgqFXHhC9q 2i0s1WD7WdDYFjM159xOxziReTOG7Lk6idzFzxxhnLrf81WiAW0SKpEcWlXslCrSSJqN 7T3m+F18bokiwyA7ZCpRJxPTbYtfztNIUeUGEOjsoqy2/McnJIWu/4H0Cu66o8FAW+c0 EurWCdwEDT0fXFU1LS9MB9+wdghPO2+EPvl0/QPutzJ/+n5aqjw3anpzRgMTpPzdRCjI 26Fwnmjaxb3GnxOjnThzS0/3NLDGOZ4QMmfaB548yctDunDgyU0e0PPIZ83A4+e4/E9A Wivg== X-Forwarded-Encrypted: i=1; AJvYcCVjMw+U26SnZjJNJmiQPI3OMIVgCHrjskA4wGq9tFjgyP5vlQPWQN0SiVSvgcS3aGOC2x6kGHQxj9CFGc3HfA==@freebsd.org X-Gm-Message-State: AOJu0YyHTmC+NMd4CKvMpj7Cpdl+ubwdEhTbwXk+sY5RgGAr1pqSSJR5 gNVossUeM/KfPSs199I28p/Lt8ex0UrzrmINmY24jYg55vH5vCasoyLeJQ== X-Google-Smtp-Source: AGHT+IG3xZf6GF7f+XIzjF7vOIWOdeKEb3uhD69cxiE10aMb2MRjdlkflVuEB+iVEAUSMdeZjRfqlA== X-Received: by 2002:a17:907:9805:b0:a90:34ba:506e with SMTP id a640c23a62f3a-a991bd71df3mr282238866b.8.1728129694586; Sat, 05 Oct 2024 05:01:34 -0700 (PDT) Received: from smtpclient.apple ([188.212.112.125]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a992e7df993sm123843766b.194.2024.10.05.05.01.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Oct 2024 05:01:33 -0700 (PDT) Content-Type: text/plain; charset=utf-8 List-Id: Production branch of FreeBSD source code List-Archive: https://lists.freebsd.org/archives/freebsd-stable List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: freebsd-stable@freebsd.org Sender: owner-freebsd-stable@FreeBSD.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3818.100.11.1.3\)) Subject: Re: uaudio device re-attach and persisting dev.pcm.$pcm.bitperfect sysctl From: Alban Hertroys In-Reply-To: Date: Sat, 5 Oct 2024 14:01:23 +0200 Cc: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= , freebsd-stable@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: <8F8158B8-4D78-4A17-90B7-659ECB9988B5@gmail.com> References: <86ploiwxw8.fsf@ltc.des.dev> <8745F9FB-9CC1-476C-9445-DC0A7A76165F@gmail.com> To: Christos Margiolis X-Mailer: Apple Mail (2.3818.100.11.1.3) X-Spamd-Result: default: False [-2.08 / 15.00]; SUBJECT_HAS_CURRENCY(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.93)[-0.928]; NEURAL_HAM_MEDIUM(-0.66)[-0.656]; MV_CASE(0.50)[]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20230601]; R_SPF_ALLOW(-0.20)[+ip6:2a00:1450:4000::/36]; MIME_GOOD(-0.10)[text/plain]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; MLMMJ_DEST(0.00)[freebsd-stable@freebsd.org]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; MID_RHS_MATCH_FROM(0.00)[]; ASN(0.00)[asn:15169, ipnet:2a00:1450::/32, country:US]; RCVD_VIA_SMTP_AUTH(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; RCVD_IN_DNSWL_NONE(0.00)[2a00:1450:4864:20::629:from] X-Rspamd-Queue-Id: 4XLPCN5fStz4tdn X-Spamd-Bar: -- > On 2 Oct 2024, at 23:53, Christos Margiolis = wrote: >=20 > Alban Hertroys wrote: >> Meanwhile, several people here suggested that devd is the way to go >> about this. I had actually looked into that a bit, but that seemed to >> require a related device node in /dev, and there=E2=80=99s neither = one for pcm >> nor for uaudio, so I discarded that as not being a viable option. >> Perhaps too soon. >=20 > Audio device nodes are /dev/dspX, where X is the unit number, which = has > a 1-1 relation with the pcmX unit number, so pcm2's device node is > /dev/dsp2. Doh! I knew that, just didn=E2=80=99t realise it while writing that devd = config. I got it working now. Here=E2=80=99s what I came up with: > cat /usr/local/etc/devd/uaudio.conf notify 100 { match "system" "USB"; match "subsystem" "DEVICE"; match "type" "ATTACH"; match "vendor" "0x152a"; match "product" "0x8750"; action "/usr/bin/touch /var/run/usb.0x152a.0x8750"; }; notify 100 { match "system" "USB"; match "subsystem" "DEVICE"; match "type" "DETACH"; match "vendor" "0x152a"; match "product" "0x8750"; action "/bin/rm -f /var/run/usb.0x152a.0x8750"; }; notify 100 { match "system" "DEVFS"; match "subsystem" "CDEV"; match "type" "CREATE"; match "cdev" "dsp[0-9]"; action "test -f /var/run/usb.0x152a.0x8750 && \ PCM=3D`echo $cdev | sed 's@^dsp@@'` && \ sysctl hw.snd.default_unit=3D${PCM} \ dev.pcm.${PCM}.play.vchans=3D0 \ dev.pcm.${PCM}.bitperfect=3D1"; }; As you can see, I build in a check that it=E2=80=99s the correct device = before starting to set sysctl=E2=80=99s, by checking against a file = created in /var/run. I=E2=80=99m not too enthusiastic about that = solution=E2=80=A6 Better suggestions are welcome. It would be nice if I could set a variable in the USB ATTACH and = =E2=80=98match=E2=80=99 that in the CDEV CREATE step to filter the rule, = or something like that. Originally I tried checking for the device using: test "`sysctl -n dev.pcm.${PCM}.%desc`" =3D 'Topping D90SE=E2=80=99= , but that statement seems to require the double-quotes for test to = accept it, which conflict with the double-quotes of the action string. I = couldn=E2=80=99t find a way to escape those inner quotes. So that=E2=80=99= s another issue I ran into, although approaches to use the USB attach = event for matching the dsp device to the usb device are clearly superior = to reading out a sysctl that=E2=80=99s an effect of it.=20 Additionally, I noticed that other people also use sed or similar to cut = the device number off the cdev variable in their devd configs. That = would have been a convenient variable to have available by default, I = think. I mean, obviously it=E2=80=99s cool that we can show off how good we are = at looking up sed expressions on Google, but as a data engineer I = can=E2=80=99t help but feel that the data that we need for these configs = could be easier to get at. All in all, I got it working, thanks to the help here. Regards, Alban Hertroys -- There is always an exception to always.