The assignment was originally created to reduce length
of one line of code (i.e. for readability). But we can
achieve this objective without adding executable code.
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch was prompted by the merge request for pgrep
referenced below. In top's case, any performance gains
will be minimal since the now defunct strncpy was only
employed for termcap rebuilds after interacting with a
user (+ 1 other non-termcap related user interaction).
[ golly, strncpy always calls at least two functions ]
[ but usually calls a total of 3. on the other hand, ]
[ memccpy will only call a maximum of two functions. ]
And thanks to Baruch Siach for these strncpy insights.
Reference(s):
https://gitlab.com/procps-ng/procps/-/merge_requests/148
Signed-off-by: Jim Warner <james.warner@comcast.net>
There was a potential problem with these macros should
that '#define SCROLLVAR_NO' be active and they were to
appear in an 'if' statement (like is necessary for the
master branch version of top under that EU_CMD label).
[ now they're always usable without requiring an ';' ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch eliminates those warnings referenced below.
They are sometimes associated with an obscure #define.
We'll also corrrect one header file function prototype
so it will aggree with the actual function definition.
Reference(s):
top.c: In function 'adj_geometry':
top.c:1874:20: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
1874 | if (Screen_cols < DOUBLE_limit) Curwin->rc.double_up = 0;
| ^
top.c: In function 'zap_fieldstab':
top.c:2359:26: warning: comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]
2359 | if (wtab[EU_CPN].wmin < digits) {
| ^
top.c:2365:26: warning: comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]
2365 | if (wtab[EU_NMA].wmin < digits) {
| ^
top.c: In function 'keys_summary':
top.c:5128:45: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
5128 | if (w->rc.double_up && Screen_cols < DOUBLE_limit) {
| ^
top.c: In function 'sum_tics':
top.c:5605:22: warning: unused variable 'num_syst' [-Wunused-variable]
5605 | int ix, num_user, num_syst;
| ^~~~~~~~
top.c:5605:12: warning: unused variable 'num_user' [-Wunused-variable]
5605 | int ix, num_user, num_syst;
| ^~~~~~~~
Signed-off-by: Jim Warner <james.warner@comcast.net>
The 'iokey' function's parameter 'action' was utilized
with literal numbers in the calling functions. So this
change will replace those literal numbers with #define
constants which, one hopes, will clarify their impact.
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch began as just an attempt to make any option
which also included an argument a little more readable
by adding one space before the '=ARGUMENT' convention.
[ by the way, i don't agree with most of those other ]
[ procps-ng programs that use an '<arg>' convention. ]
[ it's too easily misread as an 'optional' argument. ]
[ top uses a convention like that found in coreutils ]
[ albeit now with one extra space before the equals. ]
In adjusting those arguments it was apparent that many
explanations already lined up nicely at the right hand
margin. So, this commit will force right-justification
with all explanations (as we do with commit messages).
[ and as a final challenge, for those options taking ]
[ an argument, that argument was repeated within the ]
[ explanation and made the rightmost item on a line. ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
When in forest view mode, that focus toggle ('F') is a
useful tool occasionally. But, if a focused parent has
enough cloned siblings to exceed screen rows, it could
be hard to remember that such a toggle remains active.
So, this patch will provide a subtle visual clue added
to the leftmost position in the COMMAND column. Now if
the focus toggle was active, regardless of total tasks
affected, the users will always know when it's active.
Reference(s):
. -7/24/21, introduced new focus toggle
commit 3e922e671d
. 09/23/21, ensure focused tasks stay focused
commit 69978e3650
Signed-off-by: Jim Warner <james.warner@comcast.net>
In the commit referenced below, I fixed what I thought
was all the top 'truncation' warnings. For that commit
I had been using CFLAGS='-ggdb -Wall'. However, if one
uses just a vanilla './configure', then a hidden extra
warning will surface. This patch will finally kill it.
[ thanks a bunch gcc - we love this kind of behavior ]
Reference(s):
. 01/08/22, original warning fix
commit 44ca06f1a0
Signed-off-by: Jim Warner <james.warner@comcast.net>
[ you wouldn't believe how many back-and-forths were ]
[ involved in Craig convincing me there were several ]
[ inconsistencies. i am so dense sometimes (often?). ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch was prompted by Björn Fischer's merge #147
request referenced below. And since the library change
may impact all users, multiple man pages were updated.
[ and thanks to Björn for initiating this extension ]
Reference(s):
https://gitlab.com/procps-ng/procps/-/merge_requests/147
Prototyped-by: Björn Fischer <bf@CeBiTec.Uni-Bielefeld.DE>
Signed-off-by: Jim Warner <james.warner@comcast.net>
Over the years the summary_show function has increased
from around 77 lines of code & comments to its current
size of 243 lines. This is well beyond an ideal length
of available screen rows. So this patch will split it.
We'll take the cpu and memory duties and make separate
functions out of them. Of course, this will incur some
additional call overhead but, given current cpu/memory
logic, any such increase really becomes insignificant.
Now summary_show's a svelte 57 lines of code/comments.
[ this is like what was done to that do_key function ]
[ a decade ago except overhead of new function calls ]
[ plus table lookup was even less of a concern since ]
[ a human was involved, not normal iterative output. ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
In the patch referenced below the focus task logic was
improved to ensure that newly cloned tasks 'above' the
focused task did not force an effect like the up arrow
key. That commit also acknowledged that when some task
'above' ended, it *would* act like the down arrow key.
Well, with this commit a task ending 'above' a focused
task no longer distorts the focus. That's assuming the
new '#define FOCUS_HARD_Y' is specified plus the total
focused tasks does not exceed the current screen rows.
Thus, the manual scrolling with up and down arrow keys
is allowed when the total focused exceeds screen rows.
[ but keep in mind that when a focused task has been ]
[ hardened some otherwise useful toggles will not be ]
[ available. keystrokes like 'v' and even 'F' itself ]
[ can not be applied to another task with no scroll. ]
Reference(s):
. Sep, 2021 - 'focus' logic improved
commit 69978e3650
Signed-off-by: Jim Warner <james.warner@comcast.net>
This just updates the copyright dates in the documents
where I was already represented. Others are unchanged.
Signed-off-by: Jim Warner <james.warner@comcast.net>
As the issue cited below illustrates, a pids namespace
with proc mounted as subset=pid denies our library any
access to non-task data. In top's case, the result was
a fatal error message which involved "cpu statistics".
With this patch top will now assume an error involving
global cpu (stat) or memory (meminfo) data means we're
running under a restricted pids namespace. As such, an
attempt will be made to still display task level data.
[ if our assumption is incorrect, it's of no matter. ]
[ instead of a fatal error, we'll still try to offer ]
[ a user some minimally useful bit of functionality. ]
Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/227https://www.freelists.org/post/procps/three-for-newlib,1
. 1st cut at subset=pid
commit bcb837b8c7
Signed-off-by: Jim Warner <james.warner@comcast.net>
Not only does that library tweak help to simplify some
top code, but now that ps snprintf fmtstr will finally
be accurate. That is two birdies with a single pebble!
Signed-off-by: Jim Warner <james.warner@comcast.net>
The separate threads for background updates were added
to top in the commit shown below. At that time cleanup
logic was added to end-of-job processing to cancel any
active threads and destroy any semaphores then in use.
That seemed like simple good stewardship with an added
benefit of avoiding potential valgrind 'possibly lost'
warnings for 320 byte blocks. Those blocks represented
an initial stack allocation for each of three threads.
All of that worked perfectly if such code was executed
under the main thread. In other words, if the keyboard
or a signal directed to any thread was used to trigger
program end. However, it might not always be the case.
Each of those 'refresh' routines supporting a separate
thread interacts with a newlib interface. As a result,
each is required to check the library's return result.
Should some error be detected, 'error_exit' is called.
Now we've got big problems with that eoj cleanup code.
One can't 'pthread_cancel' and 'pthread_join' a thread
from withing that same thread. Thus, when an error was
returned by the library with threads active, top would
hang with no possibility of removal short of a reboot.
So, this commit only executes that cancel/join cleanup
code when we are running under the main thread. Should
program end be triggered by a library error under some
sibling thread, all such cleanup will now be bypassed.
In the latter case, we will rely on documentation that
says any thread calling exit(3) will end every thread.
[ now, the only time we'll see any valgrind warnings ]
[ is with a library error, which is the least likely ]
[ scenario for running valgrind & top to begin with. ]
[ besides, if the valgrind warnings became a problem ]
[ one could easily add a 'warning-suppression' file. ]
Reference(s):
. Sep 2021, top introduced threads
commit 29f0a674a8
Signed-off-by: Jim Warner <james.warner@comcast.net>
When multi-threading was introduced in the patch shown
below, the former calls to sigprocmask were traded for
a pthread_sigmask call. This was done unconditionally.
As a result, even when those threads weren't enabled a
need to link with libpthread was created. In hindsight
the need should only arise when top is multi-threaded.
This commit will make pthread_sigmask use conditional.
Reference(s):
. 09/2021, separate threads introduced
commit 29f0a674a8
Signed-off-by: Jim Warner <james.warner@comcast.net>
When a visual separator was added to 2 abreast summary
items in a recent commit, this bug was introduced. So,
from that earlier patch we'll revert one line of code.
The bug surfaced under an 80/even column terminal only
when that '4' toggle was off. With an an 81/odd column
screen, it existed in both single and 2 abreast modes.
[ this commit also goes the extra distance to ensure ]
[ two abreast mode maximizes available screen width. ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
In the patch referenced below, some logic was moved in
that frame_make function in an effort to overlap those
background threads with additional main thread duties.
Unfortunately, the auto-size column feature was broken
in the process. So this patch will revert a portion of
the earlier patch so as to restore the broken feature.
Reference(s):
. Sep 2021, top overlap additional processing
commit f11f43b4f7
Signed-off-by: Jim Warner <james.warner@comcast.net>
When that 'F' focus command has been applied to a task
in forest view it should remain as the topmost process
in a particular window. But without this patch that is
not guaranteed. Newly forked/cloned tasks 'above' such
a process result in task(s) appearing which shouldn't.
The effect was as if that up arrow key scrolled beyond
the topmost parent task, which would never be allowed.
[ since scrolling is permitted within a focus range, ]
[ when any task 'above' our focus/topmost task ends, ]
[ we respond as if scrolled with the down arrow key. ]
[ that result is completely appropriate. if the user ]
[ wishes to return to a focused parent, the up arrow ]
[ or home key can be used to accomplish such a goal. ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
In an effort to improve the performance & decrease the
cost of our separate background update threads we will
relocate some overhead so that it might be overlapped.
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit just ensures that at program end all those
semaphores are removed in the same order for symmetry.
From thread's view of importance, we do least to most.
Signed-off-by: Jim Warner <james.warner@comcast.net>
Rather than having those 3 separate background threads
enabled by default, we'll turn them off until somebody
chooses to activate them. That seems more appropriate.
Signed-off-by: Jim Warner <james.warner@comcast.net>
After the stage had been set in the previous patch, in
this patch we will actually implement those background
updates via 3 separate threads. The design was simple:
. the do-while loops have now been made truly infinite
. 2 semaphores per thread allow needed synchronization
. 1 semaphore will provide for each thread to sem_wait
. 1 semaphore will provide for display o/p to sem_wait
. and all 3 thread's program name was made descriptive
A complication was the potential for a signal directed
to one of our new threads. Rather than having a thread
try to deal with such signals, we pass a mask with all
signals blocked at pthread_create time. Thereafter any
subsequent signals are forwarded to the parent thread.
[ also sigprocmask was exchanged for pthread_sigmask ]
[ since warned about use "in multithreaded process". ]
[ plus we also modified each of those POSIX comments ]
[ about 2004 to agree with current signal-safety(7). ]
Sadly, after all this effort there were no performance
benefits to having separate threads. In fact there was
a measurable performance degradation when running with
ever smaller delay intervals. But even with a delay of
1/10 second the 'real' cost increase is only about 1%.
There is one way whereby any additional costs might be
eliminated (at least seemingly). One could introduce 2
separate sets of contexts for each of those 3 threads.
Then retrieval & display could be overlapped. However,
the resulting display wouldn't represent the real-time
results. Rather it would be stale by 1 delay interval.
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit sets the stage for turning three functions
into code that can support a separate thread to update
their respective data while working in the background.
It involved relocating 1 function, renaming 2 routines
and adding parameters plus return addresses to each of
three functions. Those latter changes will be required
when issuing 'pthread_create' calls in the next patch.
The final step was organizing this code into what will
become the infinite do-while loop supporting a thread.
Signed-off-by: Jim Warner <james.warner@comcast.net>
The master branch top is pretty well insulated against
signal-unsafe function calls during end-of-job action.
However, this newlib branch top had exposed himself to
a bunch of such unsafe activity in the form of 'unref'
function calls to the new library. In those guys there
will be several 'free' invocations which are not safe.
So, this commit will simply correct such an oversight.
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is an example of what can happen when this
author is waiting around for the release of our newlib
& otherwise runs out of legitimate changes to be made.
[ on the other hand, such changes surely make us run ]
[ quite a bit more efficiently, if i am not mistaken ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
This darn patch began as 1 correction to an extraneous
comma in the man document. Then, it grew to include an
adjustment for a couple of additional man page things.
After that, I figured I might as well tighten up logic
dealing with those awful gaps in the getopt_long code.
[ the error_exit mentioned in the associated comment ]
[ will only be taken when '=' ends the argv vectors! ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
For quite some time now, top has stood out like a sore
thumb regarding the approach to cmdline options & help
text. Only short options were used and that same help
text was displayed for '-h' (help) plus 'v' (version).
[ also, top 'rolled his own' when it came to parsing ]
[ options while avoiding that getopt implementation. ]
Well, with this commit all of that has changed and top
now has added a long form of his options. Additionally
he employs getopt_long() for the bulk of that parsing.
[ however, top will still avoid separate fputs calls ]
[ characteristic of other procps-ng programs when it ]
[ comes to help. rather all such text is one string. ]
Along the way, the following major getopt deficiencies
were addressed, assuming the absence of a new #define:
* an equals sign ('=') is allowed on both option forms
* whitespace is allowed before & after the equals sign
* optional arguments needn't abut their related option
for short form nor is an '=' required with either form
Signed-off-by: Jim Warner <james.warner@comcast.net>
The commit referenced below forced a return to row one
whenever there was a thread mode transition. Now, with
our new focus ('F') feature, we should adopt a similar
philosophy so as to avoid potential display anomalies.
Reference(s)
. Jun 2018, force row 1 w/ thread mode transition
commit 19ec80bd41
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch makes it possible to honor our '-H' threads
switch even when operating under that '-p' switch used
to select/filter only certain pids. Of course, what we
have done is just exploit the new library enhancement.
[ and we're pretending we don't know the enumerators ]
[ PIDS_FETCH_THREADS_TOO + PIDS_SELECT_PID are equal ]
[ to that PIDS_SELECT_PID_THREADS enumerator itself. ]
[ thankfully, those dependencies can be assured with ]
[ a 'make check-lib' which exploits ITEMTABLE_DEBUG! ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
[ we'll also eliminate a couple of references to the ]
[ repurposed 'F' command which should have gone away ]
[ with the introduction of that new 'focus' feature! ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
Ordinarily, whenever a new field is added to top, that
RCF_VERSION_ID should be bumped which then prevents an
older version of top from reading the expanded rcfile.
With this change, however, we'll keep the existing 'k'
version since we've yet to release the newlib version.
Signed-off-by: Jim Warner <james.warner@comcast.net>
As far back as release 3.2.8 (maybe even farther) this
man page used a number with each field's descriptions.
That practice caused no real harm when top was limited
to a grand total of 26 fields (thru lower case letters
of the alphabet). However, now we've reached 70 fields
and, depending on the name that's chosen, adding a new
field could result in a massive renumbering of fields.
Thus, this patch eliminates such potential by removing
all numbers from section '3a. DESCRIPTIONS of Fields'.
Signed-off-by: Jim Warner <james.warner@comcast.net>