Re: perl fctnl woes

2015-08-13 Thread Steven McDonald
Hi Tilo,

On Tue, 11 Aug 2015 17:11:13 +0200
Tilo Stritzky  wrote:

> Am I doing something silly here?  Or is there a bug?
> I see the same result on i386 and amd64. Same for /dev/sound.
> This works on a 5.5 release, but not on later releases or current.

I've been able to reproduce this with a simple C program on amd64
-current. I've tracked it down to the recent audio(4) subsystem rewrite,
which removed support for the FIOASYNC ioctl(2) (used internally by
fcntl(2)). However, this implies it should work on 5.6 and 5.7. I don't
have any such systems with audio devices available to test; are you
sure you're seeing the same behaviour on those releases?

Below is a diff that fixes the problem for me. I'm not sure if the
EINVAL on set is needed, as other drivers which don't support FIOASYNC
(drm(4), hotplug(4), random(4) and systrace(4)) appear to just ignore
that ioctl completely. I'm sure someone more experienced than I will
know the answer to that.

> Incidentally, are there perl bindings for the native sound interface
> sio_open(3)?

I wrote some low-level Perl bindings a few weeks ago:

  https://github.com/stevenjm/perl-Audio-Sndio

They're not on CPAN yet because they're not finished, mainly because
I'm not yet sure if writing a higher-level interface in pure Perl or
extending the XS code is a better approach. The low-level bindings are
usable as is, and probably a better option than talking to /dev/audio
directly.

Index: audio.c
===
RCS file: /cvs/src/sys/dev/audio.c,v
retrieving revision 1.138
diff -u -p -r1.138 audio.c
--- audio.c 29 Jul 2015 21:13:32 -  1.138
+++ audio.c 13 Aug 2015 10:35:08 -
@@ -1542,6 +1542,11 @@ audio_ioctl(struct audio_softc *sc, unsi
case FIONBIO:
/* All handled in the upper FS layer. */
break;
+   case FIOASYNC:
+   /* No async mode, so set is an error, unset is a noop. */
+   if (*(int *)addr)
+   error = EINVAL;
+   break;
case AUDIO_PERROR:
mtx_enter(&audio_lock);
*(int *)addr = sc->play.xrun / (sc->pchan * sc->bps);



perl fctnl woes

2015-08-11 Thread Tilo Stritzky
I'm trying to set up nonblocking writes to /dev/audio from within perl.
It won't let me:

$ cat ft.pl
#!/usr/bin/perl
use warnings;
use strict;
use Fcntl;

my $fh_out;
my $outfile="/dev/audio";
my $flags;

open($fh_out, ">", $outfile) or die("open $outfile: $!");

$flags=fcntl($fh_out, F_GETFL, 0) or die("fcntl GET $outfile: $!");
$flags=fcntl($fh_out, F_SETFL, $flags | O_NONBLOCK) or die("fcntl SET $outfile: 
$!");
$ ./ft.pl
fcntl SET /dev/audio: Inappropriate ioctl for device at ./ft.pl line 13.
$ 


Am I doing something silly here?  Or is there a bug?
I see the same result on i386 and amd64. Same for /dev/sound.
This works on a 5.5 release, but not on later releases or current.

Incidentally, are there perl bindings for the native sound interface
sio_open(3)?

tilo



OpenBSD 5.8 (GENERIC.MP) #1082: Sun Aug  2 22:00:55 MDT 2015
dera...@i386.openbsd.org:/usr/src/sys/arch/i386/compile/GENERIC.MP
cpu0: AMD A4-1200 APU with Radeon(TM) HD Graphics ("AuthenticAMD" 686-class, 
1024KB L2 cache) 1 GHz
cpu0: 
FPU,V86,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,NXE,MMXX,FFXSR,PAGE1GB,LONG,SSE3,PCLMUL,MWAIT,SSSE3,CX16,SSE4.1,SSE4.2,MOVBE,POPCNT,AES,XSAVE,AVX,F16C,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,OSVW,IBS,SKINIT,WDT,TOPEXT,ITSC,BMI1
real mem  = 1547792384 (1476MB)
avail mem = 1504370688 (1434MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: date 12/14/12, SMBIOS rev. 2.7 @ 0xec390 (45 entries)
bios0: vendor American Megatrends Inc. version "X102BA.209" date 08/15/2013
bios0: ASUSTeK COMPUTER INC. X102BA
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP APIC FPDT ECDT MCFG HPET SSDT SSDT CRAT SSDT SSDT SSDT 
SSDT MSDM
acpi0: wakeup devices LOM_(S4) SBAZ(S4) OHC1(S4) EHC1(S4) OHC2(S4) EHC2(S4) 
OHC3(S4) EHC3(S4) SLPB(S4)
acpitimer0 at acpi0: 3579545 Hz, 32 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
mtrr: Pentium Pro MTRR support, 8 var ranges, 88 fixed ranges
cpu0: apic clock running at 99MHz
cpu0: mwait min=64, max=64, IBE
cpu1 at mainbus0: apid 1 (application processor)
cpu1: AMD A4-1200 APU with Radeon(TM) HD Graphics ("AuthenticAMD" 686-class, 
1024KB L2 cache) 1 GHz
cpu1: 
FPU,V86,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,HTT,NXE,MMXX,FFXSR,PAGE1GB,LONG,SSE3,PCLMUL,MWAIT,SSSE3,CX16,SSE4.1,SSE4.2,MOVBE,POPCNT,AES,XSAVE,AVX,F16C,LAHF,CMPLEG,SVM,EAPICSP,AMCR8,ABM,SSE4A,MASSE,3DNOWP,OSVW,IBS,SKINIT,WDT,TOPEXT,ITSC,BMI1
ioapic0 at mainbus0: apid 3 pa 0xfec0, version 21, 24 pins
ioapic1 at mainbus0: apid 4 pa 0xfec01000, version 21, 32 pins
acpiec0 at acpi0
acpimcfg0 at acpi0 addr 0xe000, bus 0-255
acpihpet0 at acpi0: 14318180 Hz
acpiprt0 at acpi0: bus 0 (PCI0)
acpiprt1 at acpi0: bus 1 (GPP0)
acpiprt2 at acpi0: bus 2 (GPP1)
acpicpu0 at acpi0: !C2(0@400 io@0x414), C1(@1 halt!), PSS
acpicpu1 at acpi0: !C2(0@400 io@0x414), C1(@1 halt!), PSS
acpitz0 at acpi0: critical temperature is 103 degC
acpiac0 at acpi0: AC unit online
acpibat0 at acpi0: BAT0 model "X102-30" serial   type LIon oem "ASUSTek"
acpibtn0 at acpi0: PWRB
acpibtn1 at acpi0: LID_
acpibtn2 at acpi0: SLPB
acpivideo0 at acpi0: VGA_
bios0: ROM list: 0xc/0xea00
cpu0: 999 MHz: speeds: 1000 900 800 700 600 MHz
pci0 at mainbus0 bus 0: configuration mode 1 (no bios)
pchb0 at pci0 dev 0 function 0 "AMD AMD64 16h Host" rev 0x00
vga1 at pci0 dev 1 function 0 vendor "ATI", unknown product 0x9839 rev 0x00
wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
wsdisplay0: screen 1-5 added (80x25, vt100 emulation)
azalia0 at pci0 dev 1 function 1 vendor "ATI", unknown product 0x9840 rev 0x00: 
msi
azalia0: no supported codecs
pchb1 at pci0 dev 2 function 0 vendor "AMD", unknown product 0x1538 rev 0x00
ppb0 at pci0 dev 2 function 2 "AMD AMD64 16h PCIE" rev 0x00: apic 4 int 5
pci1 at ppb0 bus 1
"Atheros AR9485" rev 0x01 at pci1 dev 0 function 0 not configured
ppb1 at pci0 dev 2 function 3 "AMD AMD64 16h PCIE" rev 0x00: apic 4 int 6
pci2 at ppb1 bus 2
re0 at pci2 dev 0 function 0 "Realtek 8101E" rev 0x05: RTL8105E (0x4080), msi, 
address 74:d0:2b:6b:22:d0
rlphy0 at re0 phy 7: RTL8201E 10/100 PHY, rev. 2
xhci0 at pci0 dev 16 function 0 vendor "AMD", unknown product 0x7814 rev 0x01: 
msi
usb0 at xhci0: USB revision 3.0
uhub0 at usb0 "AMD xHCI root hub" rev 3.00/1.00 addr 1
ahci0 at pci0 dev 17 function 0 "AMD Hudson-2 SATA" rev 0x40: msi, AHCI 1.3
ahci0: port 0: 6.0Gb/s
scsibus1 at ahci0: 32 targets
sd0 at scsibus1 targ 0 lun 0:  SCSI3 0/direct fixed 
naa.50025388a00a9dfa
sd0: 114473MB, 512 bytes/sector, 234441648 sectors, thin
ohci0 at pci0 dev 18 function 0 "AMD Hudson-2 USB" rev 0x39: apic 3 int 18, 
version 1.0, legacy support
ehci0 at pci0 dev 18 function 2 "AMD Hudson-2 USB2" rev 0x39: apic 3 int 17
usb1 at ehci0: USB revision 2.0
uhub1 at usb1 "AMD EHCI root hub" rev 2.00/1.00 addr 1
ohci1 at pci0 dev 19 function 0 "AMD Huds