On Sun, Jul 24, 2022 at 10:34:04AM -0700, Andrew Hewus Fresh wrote:
> On Sun, Jul 24, 2022 at 09:14:30AM -0700, Andrew Hewus Fresh wrote:
> > On Sun, Jul 24, 2022 at 10:01:26AM -0600, Theo de Raadt wrote:
> > > Jonathan Gray <[email protected]> wrote:
> > > 
> > > > On Sun, Jul 24, 2022 at 08:05:26AM -0600, Theo de Raadt wrote:
> > > > > Why not match on cpu0: .*Intel
> > > > 
> > > > I sent a diff a month ago with ^cpu0:*Intel(R)
> > > > 
> > > > semarie mentioned false positives as it could match another
> > > > Intel device on another line on a non-Intel CPU
> > > > 
> > > > https://marc.info/?l=openbsd-tech&m=165579653107768&w=2
> > > 
> > > Well, then fw_update should be fixed to not perform the match over
> > > multiple lines.
> > 
> > I'm looking at fixing fw_update to match each line instead of the whole
> > dmesg.  I'll try to get a patch out for that today.
> 
> This patch matches patterns against each line in the dmesg instead of
> anchoring on newlines and matching against the entire string at once
> anchored by newlines.  This would mean that ^cpu0:*Intel(R) would Just
> Work.
> 
> The problem is that it's a little over 3 times slower on my laptop to do
> the matching this way.


As an example, on my alpha (that I admit to only keeping around because
a 166MHz single processor machine that runs OpenBSD is useful for
testing how things work on a slow machine), the current code runs and
doesn't find any firmware in 5.5 seconds and with this patch it now
takes 17.5 seconds.


> If any ksh folks have tricks to speed that up,
> I'd appreciate it.  I'll try to think about whether I can build a sed
> program that will spit out matches.  Sadly at the moment, distracted by
> a non-computer project that has been taking up all my free time.
> Hopefully that will be finished in the next couple weeks though.
> 
> I think I could do some magic to replace the "^cpu:*Intel(R)" above with
> "^cpu:*([!\n])Intel(R)" (although not with directly as ksh wouldn't
> recognize it).  That would be annoying to implement though, but would
> then still be able to do the faster single match.
> 
> 
> --- fw_update.sh.orig Sun Jul 24 10:07:40 2022
> +++ fw_update.sh      Sun Jul 24 10:14:21 2022
> @@ -168,21 +168,31 @@
>  }
>  
>  firmware_in_dmesg() {
> -     local _d _m _line _dmesgtail _last='' _nl=$( echo )
> +     local _d _m _line _dmesgtail _last='' _oldifs="$IFS"
>  
> +     IFS='
> +'
>       # The dmesg can contain multiple boots, only look in the last one
> -     _dmesgtail="$( echo ; sed -n 'H;/^OpenBSD/h;${g;p;}' 
> /var/run/dmesg.boot )"
> +     set -A _dmesgtail $( sed -n 'H;/^OpenBSD/h;${g;p;}' /var/run/dmesg.boot 
> )
> +     IFS="$_oldifs"
>  
>       grep -v '^[[:space:]]*#' "$FWPATTERNS" |
>           while read -r _d _m; do
>               [ "$_d" = "$_last" ] && continue
> -             [ "$_m" ]             || _m="${_nl}${_d}[0-9] at "
> -             [ "$_m" = "${_m#^}" ] || _m="${_nl}${_m#^}"
> -
> -             if [[ $_dmesgtail = *$_m* ]]; then
> -                     echo "$_d"
> -                     _last="$_d"
> +             [ "$_m" ] || _m="^${_d}[0-9] at "
> +             if [ "$_m" = "${_m#^}" ]; then
> +                     _m="*$_m"
> +             else
> +                     _m="${_m#^}"
>               fi
> +
> +             for _line in "${_dmesgtail[@]}"; do
> +                     if [[ $_line = $_m* ]]; then
> +                             echo "$_d"
> +                             _last="$_d"
> +                             break
> +                     fi
> +             done
>           done
>  }
>  
> 

-- 
andrew

A printer consists of three main parts:
        the case, the jammed paper tray and the blinking red light.

Reply via email to