<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: calculate decimal value for a tunable in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/calculate-digital-value-for-a-tunable/m-p/3972643#M95429</link>
    <description>&lt;P&gt;&amp;gt;i've tried to calculate the values with awk but there is no recusivity.&lt;BR /&gt;&lt;BR /&gt;awk allows recursion for functions. Just convert every variable into a function. Then it is evaluated just in time.&lt;BR /&gt;&lt;BR /&gt;Or convert them to C macros and compile with the bundled C compiler. Just print the macro values out.&lt;BR /&gt;Macro processing allows nesting.&lt;BR /&gt;&lt;BR /&gt;Or give up on 11.11 go to 11.23 where kctune gives everything in terms of numbers.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Oct 2011 11:05:31 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2011-10-07T11:05:31Z</dc:date>
    <item>
      <title>calculate digital value for a tunable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/calculate-digital-value-for-a-tunable/m-p/3972642#M95428</link>
      <description>&lt;!--!*#--&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;i search a way for calculate values of tunable parameters for integration in a script, my problem is from formula.&lt;BR /&gt;&lt;BR /&gt;i've tried sysdef but there's not all values (maxusers, nstrtel, etc...)&lt;BR /&gt;&lt;BR /&gt;i've tried to calculate the values with awk but there is no recusivity.&lt;BR /&gt;&lt;BR /&gt;ie. If NPROC is a degital value recovered from kmtune i know how to calculate :&lt;BR /&gt;((16*NPROC)+2048)&lt;BR /&gt;but not if NPROC is another formula, recursivity problem.&lt;BR /&gt;&lt;BR /&gt;do you have any scripts or commands which is able to return the digital values of tunables?&lt;BR /&gt;&lt;BR /&gt;for hexa values i use:&lt;BR /&gt;echo "0x04000000=D" |adb&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Cedrick Gaillard&lt;BR /&gt;</description>
      <pubDate>Fri, 30 Mar 2007 04:01:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/calculate-digital-value-for-a-tunable/m-p/3972642#M95428</guid>
      <dc:creator>totoperdu</dc:creator>
      <dc:date>2007-03-30T04:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: calculate decimal value for a tunable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/calculate-digital-value-for-a-tunable/m-p/3972643#M95429</link>
      <description>&lt;P&gt;&amp;gt;i've tried to calculate the values with awk but there is no recusivity.&lt;BR /&gt;&lt;BR /&gt;awk allows recursion for functions. Just convert every variable into a function. Then it is evaluated just in time.&lt;BR /&gt;&lt;BR /&gt;Or convert them to C macros and compile with the bundled C compiler. Just print the macro values out.&lt;BR /&gt;Macro processing allows nesting.&lt;BR /&gt;&lt;BR /&gt;Or give up on 11.11 go to 11.23 where kctune gives everything in terms of numbers.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2011 11:05:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/calculate-digital-value-for-a-tunable/m-p/3972643#M95429</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-10-07T11:05:31Z</dc:date>
    </item>
    <item>
      <title>Re: calculate digital value for a tunable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/calculate-digital-value-for-a-tunable/m-p/3972644#M95430</link>
      <description>&lt;!--!*#--&gt;I was also tired as you of kmtune's display of formulars.&lt;BR /&gt;But more than that I needed them to be evaluated automatically when having automated kernel generation from a conf file of new to establish kernel tunables.&lt;BR /&gt;I have done this by a wee Perl script.&lt;BR /&gt;Because it partly is not very portable (due to lack of time) and thus was never meant for publication I can only post here some more general snippets just to give you an idea&lt;BR /&gt;(I'm sure you will do better).&lt;BR /&gt;&lt;BR /&gt;(I urge you, if you want to make use of it to use the strict and warnings pragma, which I omit here for brevity)&lt;BR /&gt;First this is a sub that simply parses the output of kmtune and pushes it into a LoL.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;sub get_tunables {&lt;BR /&gt;    my (@dump, %parms);&lt;BR /&gt;    chomp(@dump = qx(/usr/sbin/kmtune));&lt;BR /&gt;    splice @dump, 0, 2;&lt;BR /&gt;    map {&lt;BR /&gt;          $parms{$_-&amp;gt;[0]} = {current =&amp;gt; $_-&amp;gt;[1] =~ /^\d+$/ ? $_-&amp;gt;[1] : undef,&lt;BR /&gt;                             dynamic =&amp;gt; $_-&amp;gt;[2] eq 'Y' ? 1 : 0,&lt;BR /&gt;                             pending =&amp;gt; $_-&amp;gt;[3]}&lt;BR /&gt;        } map [split], @dump;&lt;BR /&gt;    my @formula_pending = grep $parms{$_}{pending} =~ m@[()/*+-]@, keys %parms;&lt;BR /&gt;    return %parms;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;would be used like so&lt;BR /&gt;&lt;BR /&gt;my %parms = get_tunables();&lt;BR /&gt;&lt;BR /&gt;Because the LoL admitedly isn't quite handy,&lt;BR /&gt;but more than that because on my servers only the pending values displayed by kmtune exhibit the formula noise, one could strip this column into a separate hash that I name %pending here.&lt;BR /&gt;&lt;BR /&gt;%pending = map {$_=&amp;gt;$parms{$_}{pending}} keys %parms;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Then I defined another sub that actually does a recursive evaluation of formular tainted tunables which it expects to be passed as first arg as a string scalar.&lt;BR /&gt;The second arg is hash of tunables,&lt;BR /&gt;i.e. in the example above %pending;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;sub eval_formula {&lt;BR /&gt;    my ($expr, %parms) = @_;&lt;BR /&gt;    my $eval_this;&lt;BR /&gt;    my $parm = '';&lt;BR /&gt;    foreach my $char ($expr =~ /./g) {&lt;BR /&gt;        if ($char =~ m@[\d\s()*/+-]@) {&lt;BR /&gt;            if (exists $parms{"\L$parm\E"}) {&lt;BR /&gt;                $eval_this .= $parms{"\L$parm\E"};&lt;BR /&gt;                $parm = '';&lt;BR /&gt;            }&lt;BR /&gt;            $eval_this .= $char;&lt;BR /&gt;        }&lt;BR /&gt;        else {&lt;BR /&gt;            $parm .= $char;&lt;BR /&gt;        }&lt;BR /&gt;    }&lt;BR /&gt;    if ($eval_this =~ m{^[\d\s()*/+-]+$}) {&lt;BR /&gt;        $parm = eval $eval_this;&lt;BR /&gt;    }&lt;BR /&gt;    else {&lt;BR /&gt;        $parm = eval_formula($eval_this, %parms);&lt;BR /&gt;    }&lt;BR /&gt;    return int($parm + 0.5);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;To reduce invocation of above eval_formula() function to only those tunables tainted one could grep those into a separate hash, &lt;BR /&gt;that I call %eval_these here.&lt;BR /&gt;&lt;BR /&gt;%eval_these = map { $_ =&amp;gt; $pending{$_} } grep $pending{$_}=~m|[()/*+-]|, keys %pending;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;To show you its contents here is a dump from a debugger session of it.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;  DB&amp;lt;12&amp;gt; |x \%eval_these&lt;BR /&gt;0  HASH(0x800000010050bef0)&lt;BR /&gt;   'bufpages' =&amp;gt; '(NBUF*2)'&lt;BR /&gt;   'dnlc_hash_locks' =&amp;gt; '4*128'&lt;BR /&gt;   'effective_maxpid' =&amp;gt; '((NPROC&amp;lt;=30000)?30000:(NPROC*5/4))'&lt;BR /&gt;   'ksi_alloc_max' =&amp;gt; '(NPROC*8)'&lt;BR /&gt;   'msgmap' =&amp;gt; '(2+MSGTQL)'&lt;BR /&gt;   'ncallout' =&amp;gt; '(16+NKTHREAD)'&lt;BR /&gt;   'nclist' =&amp;gt; '(100+16*MAXUSERS)'&lt;BR /&gt;   'ncsize' =&amp;gt; '(NINODE+VX_NCSIZE)+(8*DNLC_HASH_LOCKS)'&lt;BR /&gt;   'netisr_priority' =&amp;gt; '-1'&lt;BR /&gt;   'nfile' =&amp;gt; '(16*(NPROC+16+MAXUSERS)/10+32+2*(NPTY+NSTRPTY+NSTRTEL))'&lt;BR /&gt;   'ninode' =&amp;gt; '((NPROC+16+MAXUSERS)+32+(2*NPTY))'&lt;BR /&gt;   'nkthread' =&amp;gt; '(((NPROC*7)/4)+16)'&lt;BR /&gt;   'nproc' =&amp;gt; '(20+8*MAXUSERS)'&lt;BR /&gt;   'nsysmap' =&amp;gt; '((NPROC)&amp;gt;800?2*(NPROC):800)'&lt;BR /&gt;   'nsysmap64' =&amp;gt; '((NPROC)&amp;gt;800?2*(NPROC):800)'&lt;BR /&gt;   'semmap' =&amp;gt; '(SEMMNI+2)'&lt;BR /&gt;   'timeslice' =&amp;gt; '(100/10)'&lt;BR /&gt;   'vol_dcm_replay_size' =&amp;gt; '(256*1024)'&lt;BR /&gt;   'vol_max_nmpool_sz' =&amp;gt; '(4*1024*1024)'&lt;BR /&gt;   'vol_max_rdback_sz' =&amp;gt; '(4*1024*1024)'&lt;BR /&gt;   'vol_max_vol' =&amp;gt; '(8*1024*1024)'&lt;BR /&gt;   'vol_min_lowmem_sz' =&amp;gt; '(512*1024)'&lt;BR /&gt;   'vol_nm_hb_timeout' =&amp;gt; '(10)'&lt;BR /&gt;   'vol_vvr_transport' =&amp;gt; '(1)'&lt;BR /&gt;   'vol_vvr_use_nat' =&amp;gt; '(0)'&lt;BR /&gt;   'voliomem_chunk_size' =&amp;gt; '(64*1024)'&lt;BR /&gt;   'voliomem_maxpool_sz' =&amp;gt; '(4*1024*1024)'&lt;BR /&gt;  DB&amp;lt;13&amp;gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Ugly, isn't it?&lt;BR /&gt;&lt;BR /&gt;Now I have a problem which my code doesn't handle yet.&lt;BR /&gt;Take a look at the value of nsysmap.&lt;BR /&gt;This contains a shorthand if else block as it seems.&lt;BR /&gt;Luckily Perl has almost an identical so called ternary operator, viz. " expr ? val1 : val2 ".&lt;BR /&gt;&lt;BR /&gt;  'nsysmap' =&amp;gt; '((NPROC)&amp;gt;800?2*(NPROC):800)'&lt;BR /&gt;&lt;BR /&gt;So you can easily fix this.&lt;BR /&gt;I for now simply wipe these inerfering tunable from my hash of tainted params&lt;BR /&gt;(this is rather sloppy and should be done in a more maintainable manner).&lt;BR /&gt;&lt;BR /&gt;delete @eval_these{grep($eval_these{$_}=~/\?/,keys %eval_these)};&lt;BR /&gt;&lt;BR /&gt;Also note, that you may have to convert hex numbers.&lt;BR /&gt;If these were given as literals Perl would convert them automatically.&lt;BR /&gt;But since they are read in from a pipe to kmtune one needs to use the Perl functions oct() or hex().&lt;BR /&gt;&lt;BR /&gt;map $pending{$_} = hex($pending{$_}),&lt;BR /&gt;    grep $pending{$_} =~ /^0[xX]/, keys %pending;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Finally, one can evaluate all in %eval_these in a loop.&lt;BR /&gt;&lt;BR /&gt;foreach my $eval_this (keys %eval_these) {&lt;BR /&gt;    $evaled{$eval_this} = &lt;BR /&gt;        eval_formula($eval_these{$eval_this}, %pending);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Here the contents of %evaled after that loop in a debugger session.&lt;BR /&gt;&lt;BR /&gt;  DB&amp;lt;11&amp;gt; !10&lt;BR /&gt;x \%evaled&lt;BR /&gt;0  HASH(0x800000010058c488)&lt;BR /&gt;   'bufpages' =&amp;gt; 0&lt;BR /&gt;   'dnlc_hash_locks' =&amp;gt; 512&lt;BR /&gt;   'ksi_alloc_max' =&amp;gt; 2208&lt;BR /&gt;   'msgmap' =&amp;gt; 42&lt;BR /&gt;   'ncallout' =&amp;gt; 515&lt;BR /&gt;   'nclist' =&amp;gt; 612&lt;BR /&gt;   'ncsize' =&amp;gt; 5596&lt;BR /&gt;   'netisr_priority' =&amp;gt; 0&lt;BR /&gt;   'nfile' =&amp;gt; 910&lt;BR /&gt;   'ninode' =&amp;gt; 476&lt;BR /&gt;   'nkthread' =&amp;gt; 499&lt;BR /&gt;   'nproc' =&amp;gt; 276&lt;BR /&gt;   'semmap' =&amp;gt; 66&lt;BR /&gt;   'timeslice' =&amp;gt; 10&lt;BR /&gt;   'vol_dcm_replay_size' =&amp;gt; 262144&lt;BR /&gt;   'vol_max_nmpool_sz' =&amp;gt; 4194304&lt;BR /&gt;   'vol_max_rdback_sz' =&amp;gt; 4194304&lt;BR /&gt;   'vol_max_vol' =&amp;gt; 8388608&lt;BR /&gt;   'vol_min_lowmem_sz' =&amp;gt; 524288&lt;BR /&gt;   'vol_nm_hb_timeout' =&amp;gt; 10&lt;BR /&gt;   'vol_vvr_transport' =&amp;gt; 1&lt;BR /&gt;   'vol_vvr_use_nat' =&amp;gt; 0&lt;BR /&gt;   'voliomem_chunk_size' =&amp;gt; 65536&lt;BR /&gt;   'voliomem_maxpool_sz' =&amp;gt; 4194304&lt;BR /&gt;  DB&amp;lt;12&amp;gt;&lt;BR /&gt;&lt;BR /&gt;Finally, if you wish you can rejoin the hashes like&lt;BR /&gt;(note, not pretty efficient but the hashes are rather small)&lt;BR /&gt;&lt;BR /&gt;%numeric_pending = (%pending, %evaled);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;My sample snippets are far from production proof but I hope that they suffice as an example how this could be dealt with in Perl.&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Ralph&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 30 Mar 2007 07:37:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/calculate-digital-value-for-a-tunable/m-p/3972644#M95430</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2007-03-30T07:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: calculate digital value for a tunable</title>
      <link>https://community.hpe.com/t5/operating-system-linux/calculate-digital-value-for-a-tunable/m-p/3972645#M95431</link>
      <description>&lt;!--!*#--&gt;Thanks for your inputs.&lt;BR /&gt;&lt;BR /&gt;Denis, i've very few knoledge in awk functions but according to the man page, it seems not so complicated, i'll try it.&lt;BR /&gt;&lt;BR /&gt;Ralph, your solution is great because almost ready to use, i like it ;)&lt;BR /&gt;&lt;BR /&gt;for your value:&lt;BR /&gt;'nsysmap' =&amp;gt; '((NPROC)&amp;gt;800?2*(NPROC):800)'&lt;BR /&gt;awk can count it very well:&lt;BR /&gt;#&amp;gt; awk -v NPROC=8212 'BEGIN{print "NSYSMAP:"((NPROC)&amp;gt;800?2*(NPROC):800)}' &lt;BR /&gt;NSYSMAP:16424&lt;BR /&gt;&lt;BR /&gt;i've wrote a script that can calculate the kmtune values but the formula behind, this is:&lt;BR /&gt;---&amp;lt;----------&lt;BR /&gt;# i start by unset all future var.&lt;BR /&gt;kmtune |egrep -v "^Parameter|^=====|^$|\?" | \&lt;BR /&gt;while read param val&lt;BR /&gt;do&lt;BR /&gt;unset $param&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;NOTGOOD=false&lt;BR /&gt;&lt;BR /&gt;while [ -n "$NOTGOOD" ]&lt;BR /&gt;do&lt;BR /&gt;NOTGOOD=&lt;BR /&gt;kmtune |egrep -v "^Parameter|^=====|^$|\?" | \&lt;BR /&gt;awk '{print tolower($1)"="tolower($2)}' | \&lt;BR /&gt;while IFS='=' read -r param val&lt;BR /&gt;do&lt;BR /&gt;# if value start by 0X, it's hexa, i need to convert:&lt;BR /&gt;  if [ "$(echo $val |egrep -ci "^0x")" = "1" ]&lt;BR /&gt;    then&lt;BR /&gt;      val="$(echo "${val}=D" |adb)"&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;#if value is alpha, it's a formula i nees to calculate&lt;BR /&gt;  if [ "$(echo $val |egrep -c "[[:alpha:]_]")" = "1" ]&lt;BR /&gt;    then&lt;BR /&gt;      NOTGOOD=&lt;BR /&gt;      for PARAM in $(echo $val |sed 's/[^[:alpha:]_]/ /g')&lt;BR /&gt;      do&lt;BR /&gt;# if i've not the var value, i restart the loop&lt;BR /&gt;        if [ -z "$(eval echo \$$PARAM)" ]&lt;BR /&gt;          then&lt;BR /&gt;            NOTGOOD=true&lt;BR /&gt;            break&lt;BR /&gt;        fi&lt;BR /&gt;      done&lt;BR /&gt;        if [ -z "$NOTGOOD" ]&lt;BR /&gt;          then&lt;BR /&gt;            eval "$param=\$(($val))"&lt;BR /&gt;        fi&lt;BR /&gt;    else&lt;BR /&gt;      eval $param="\$val"&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;# easy to test&lt;BR /&gt;echo $nfile&lt;BR /&gt;echo $msgmap&lt;BR /&gt;---&amp;lt;----------&lt;BR /&gt;&lt;BR /&gt;i now need to change the shell calcul by awk for calculate formula like ((NPROC)&amp;gt;800?2*(NPROC):800) and all will be fine.&lt;BR /&gt;&lt;BR /&gt;thanks all for your help/ideas.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Cedrick Gaillard&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Apr 2007 04:49:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/calculate-digital-value-for-a-tunable/m-p/3972645#M95431</guid>
      <dc:creator>totoperdu</dc:creator>
      <dc:date>2007-04-02T04:49:50Z</dc:date>
    </item>
  </channel>
</rss>

