Commit Graph

74 Commits

Author SHA1 Message Date
Jim Warner
87bb21b557 top: fix selected miscellaneous compiler warnings
These per instance warnings have been eliminated:
warning: range expressions in switch statements are non-standard
warning: padding struct to align 'winflags'
warning: dereferencing type-punned pointer will break strict-aliasing rules

   These per instance warnings have not been addressed
   since they simply trade one warning for another:
      From:
warning: ISO C does not permit named variadic macros
warning: ISO C does not support the '%Lu' gnu_scanf format
      To:
warning: anonymous variadic macros were introduced in C99
warning: ISO C90 does not support the 'll' gnu_scanf length modifier

   Lastly, since all C compilers have supported use of
   C++ style comments for the past 20 years, the top
   program will never trade them for the often more
   cumbersome C style comments simply to avoid this
   once per source file warning:
warning: C++ style comments are not allowed in ISO C90

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-06 11:05:42 +11:00
Jim Warner
0053eefbb9 top: extend rcfile conversions for '--enable-oomem'
Under openSUSE, old top uses additional fields for
out-of-memory reporting.  As a result, under the
original approach to rcfile conversion, new top would
issue a fatal corrupt window entry message asking that
the rcfile be deleted.

This patch extends the conversion range to include
the extra openSUSE field characters.  It's effective
when ./configure specifies the --enable-oomem option
which in turn defines OOMEM_ENABLE.

This commit also makes the conversion logic slightly
more forgiving.  While enforcing an upper limit on the
expected number of old style field characters, amounts
less than that will be handled seemlessly.

Reference:
commit 4b98733132

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-03 14:01:35 +11:00
Jim Warner
4b98733132 top: honor the restrictive, crufty old top rcfile
At one time, new top silently defaulted when an rcfile
was found to be incompatible.  This is exactly what
the old top did.  However, after some discussion it
was decided top should alert the user and thereby
save the system administrator some headaches.

Now, some are upset over the fatal error, proving you
can't please everybody.  But in all fairness, given
the difficulty of customizing old top, any reluctance
to delete an old saved rcfile is understandable.

To ease transition to this new top, old style rcfiles
will now be honored and converted to the new format.
And if not disabled at ./configure time via CFLAGS,
a user will be warned when an old style rcfile is
about to be overwritten using the 'W' command.

Lastly, the config validation logic was enhanced to
help ensure both types of rcfile haven't been edited
manually and possibly made unuseable.

Reported-By: sergio <mailbox@sergio.spb.ru>
Bug-Debian:  http://bugs.debian.org/651213

Reported-By: martin f krafft <madduck@debian.org>
Bug-Debian:  http://bugs.debian.org/651863

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-02 21:29:43 +11:00
Jim Warner
efb9fcb816 top: relocate a prototype to prevent compiler warning
Until the 'locate/search' provisions were added,
top avoided the need for any function prototypes
through careful source file organization.  But
the addition of the find_string function required
a prototpe for task_show, lest a massive file
reorganization be undertaken.

This commit moves the actual protype out of top.h
and places it adjacent to the caller in order to
avoid a warning when top_nls.c is compiled.

References:
commit 270e8e7eeb
commit d6e6a9aa38

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-28 08:45:44 +11:00
Jim Warner
4dac0dfeb1 top: isolate #defines actually present in confiure.ac
All top.h defines were lumped together as:
   'Development/Debugging defines'

This commit establishes this new category:
   'Defines represented in configure.ac'

And that new category now contains OOMEM_ENABLE,
which enables the SuSE out-of-memory additions

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-28 08:45:35 +11:00
Jim Warner
045538e01b top: remove residual logic for obsolete functionality
At one time the 'open_psdb_message' library call was
supported with the concept of a postponed message
which would display after top startup completed.
In turn, that required logic to strip the '\n' which
was embedded (inappropriately) in any such message.

Nowdays top treats such a returned error as fatal so
there is no need for the 'strim' function which is
being removed with this commit.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-28 08:45:12 +11:00
Jim Warner
ee3ed4b45e top: update latest CPU % distortions understanding
We originally approached the potential problem of
% CPU distortions as unique to Nehalem type cpus.
The latest information suggests that it may have
been due to a kernel anomaly that has since been
corrected.

Yet even without such a cpu, wide disparities in
tics allocation among all available cpus have
sometimes been observed -- spikes as it were in
the normal pattern.  This has happened under both
version 2.26.38-13 and 3.0.0-15 kernels.

The small amount of additional code addressing the
original problem carries very little overhead.  It
is being retained to afford protection against any
future tic accounting aberrations.

In this commit, supporting programmer comments have
been divorced from any particular cpu type.  Also,
another variable and manifest constant will now be
eliminated when CPU_ZEROTICS is defined.

References:
commit 02508b3d76
http://www.freelists.org/post/procps/CStates-handling-new-switch,50
2012-02-28 08:45:07 +11:00
Jim Warner
a096fec8c0 top: extend the Copyright (c) dates to include 2012
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-12 21:52:23 +11:00
Jim Warner
d0e16acf15 top: reorganize some fields management logic
The calibrate_fields function had grown too large and
was adversly impacting maintainence.  So half of the
logic was split out into a new function.

Now, maintainence of column headers and the required
library flags is organized as follows:

 . adj_geometry   (calibrate_fields helper)
     provides low-level support for sigwinch, memory

 . build_headers  (calibrate_fields helper)
     constructs the headers and library flags

 . calibrate_fields
     establishes which fields will be displayed

( note the alpha order mentioned in a prior commit )

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-12 21:52:23 +11:00
Jim Warner
270e8e7eeb top: standardize names of all 'helper' functions
The top program is carefully organized into sections
and those sections are carefully placed so as to avoid
the need for prototypes. *

Additionally, names of functions are carefully chosen
to maintain alphabetical order within each section.

The names of most 'helper' functions, which are always
placed immediately above the calling functions, often
only met the spirit of the alphabetical law, not the
actual letter of that law.

This commit alters the names of such helper functions
so as to mainatin strict ascii alphabetical order
within each section.

* the single exception to prototypes is find_string,
  which calls the task_show function, and would have
  prompted a massive reorganization.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-12 21:52:23 +11:00
Jim Warner
02508b3d76 top: use CPU_ZEROTICS to embrace the Nehalem logic
The recently added logic dealing with "missing" tics
is mutually exclusive with logic associated with a
define called CPU_ZEROTICS.

This commit expands the use of that define to exclude
such Nehalem logic as appropriate.

It also extends programmer notes in top.h to include
an attribution for initiating the topic of potential
Nehalem type % CPU distortions, acknowledging:
  Jaromir Capik, <jcapik@redhat.com>

References
commit ce1410a51a
commit 9e7dd43ab7
commit a9041a5526
2012-02-12 21:52:23 +11:00
Jim Warner
ce1410a51a top: fixup logic for Nehalem cpu 'idle' threshold
Due to a poorly constructed temporary fprintf
used during development, an earlier commit went
a little too far in its computations.  The net
result was the code looked nice but actually
accomplished nothing.

It is the /proc/stat line 1 (summary line)
whose tics must be used in establishing the
threshold boundary.  And that calculation
need be performed just once per frame.

This commit ensures one threshold calculation
per delay interval no matter how many cpus
are ultimately displayed.

It also corrects scalability by factoring in
the total number of online processors.

Reference:
commit 9e7dd43ab7
2012-02-10 07:01:10 +11:00
Jim Warner
9e7dd43ab7 top: tweak the new 'reduce % CPU distortions' algorithm
The original approach to potential % CPU distortion due
to Nehalem type cores being turned off completely when
idle worked ok until the user typed something.

At that point, elapsed tics would no longer equal the
calculated value producing an undesirable 100% idle
condition until the next update or <Enter/Space> key.

This commit employs actual elapsed tics in determining
whether a cpu should be considered idle and thus makes
top's individual cpu display immune to user keystrokes.
2012-02-08 21:00:00 +11:00
Jim Warner
a9041a5526 top: reduce % CPU distortions when a core was turned off
This patch provides for cpu cores which can be turned
off completely when idle (Nehalem, etc.) thus registering
very few or no tics since the last update cycle.

When CPU_ZEROTICS is not defined (the default), any
displayed cpu with less than a certain amount of total
tics will show as 100% idle.  That amount is tempered
by the delay interval and total number of cpus.

This commit also satisfies the Debian 'top_nohz' patch
(11/24/09) in a slightly more efficient manner.  That
patch concerned kernels built with CONFIG_NO_HZ.

Reference:
http://www.freelists.org/post/procps/CStates-handling-new-switch,4
2012-02-08 20:57:58 +11:00
Jim Warner
f348575edc top: tolerate loss of smp cpus, improve CPU_t management
Prior to this patch, top was able to handle any hotplugged
cpus *added* to the system in two distinct ways.

 1) Newly added cpus would be detected by sysinfo_refresh
    calling the library's cpuinfo function, which occurs
    at most every 5 minutes.

 2) The user could force a refresh using either the
    <Enter> or <Space> keys.

Unfortunately, the *loss* of a cpu would produce an early
exit due to a /proc/stat read failure.  Such a failure
can be produced in the following way:
  sudo echo 0 > /sys/devices/system/cpu/cpu??/online

This commit allows top to tolerate the loss of cpus.
It also provides for more efficient CPU_t management,
especially for massively parallel cpu environments.

Note: Changes to the cpu compliment can produce a single
cycle distortion of cpu percentages.  Such distortion is
most visible when each cpu is being displayed.  It can
be eliminated with a forced refresh via <Enter>/<Space>.
2012-02-08 20:57:51 +11:00
Jim Warner
b73a423cc2 top: avoid %cpu distortions when toggling task/thread modes
This commit addresses a long standing buglet (debian #441166) which
surfaces when the display mode is switched between task and threads.

An extra procps refresh is now forced upon such a transition which
parallels the approach used at startup for the exact same reason.

Reference: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=441166
2012-01-14 00:04:46 +11:00
Jim Warner
e64b6f70d7 top: update some programmer documentation (no logic, just comments)
This commit corrects some outdated programmer comments.

Additionally, certain nls justifications might become
increasingly obscure with the passage of time so some
previous nls commit text has been added as comments.
2012-01-04 08:58:54 +11:00
Jim Warner
edb71e5044 top: made prolog comments like those in procps:master 2011-12-22 23:48:05 +11:00
Jim Warner
acd73a1365 top: provided for nls table integrity validation 2011-12-22 23:48:05 +11:00
Jim Warner
fe7069dff0 top: corrected double #include missed at rebase 2011-12-22 23:48:05 +11:00
Jim Warner
434198e6e4 top: corrected missed escape seq from redesign 2011-12-22 23:48:05 +11:00
Jim Warner
bc0f73e335 top: added #include of proc/readproc.h to top.h 2011-12-22 23:48:04 +11:00
Jim Warner
3f7468082a top: finalized top nls support (or so he thought)
summary of changes:
. adopted relative paths to 'include' and 'proc'
  dirs so that stand alone compiles are made
  easier and no one need guess their locations

. corrected several names for enums and macro
  usage reflecting fmt vs. txt

. expanded all octal escape sequences to a full
  3 digits since one already required 3 digits

. finalized translator hints (for now)

programming note:
  as an aside, by not including an argument for
  the gettext --add-comments, any preceeding c
  style comment will be propagated to the .pot
  file, if the gettext macro isn't empty.

  /* Need Not Say 'TRANSLATORS' ...
  snprintf(buf, sizeof(buf), "%s", _(   // unseen
  /* Translator Hint: ...
  snprintf(buf, sizeof(buf), "%s", _("" // seen
2011-12-22 23:48:04 +11:00
Jim Warner
32a9adbc13 top: provide extensive, generalized nls support
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Jim Warner <james.warner@comcast.net>
2011-12-22 23:48:04 +11:00