summaryrefslogtreecommitdiff
path: root/sys/src/9/port/proc.c
AgeCommit message (Collapse)Author
2022-09-259/port: revert timer wheel change, breaks pi4 boot, needs more time ↵cinap_lenrek
investigating
2022-09-249/port: reimplement timers to use timer wheelOri Bernstein
when many processes go to sleep, our old timer would slow to a crawl; this new implementation does not.
2022-09-03kernel: half NERR, refcount Note's to avoid excessive allocations for ↵cinap_lenrek
postnotepg() Half NERR stack to 32. When posing a note to a large group, avoid allocating Notes for each individual process, but post the reference instread. factor out process interruption into procinterrupt(). Avoid allocation of notes in alarmkproc, just posting the same note to everyone.
2022-08-17kernel: allocate notes in heapcinap_lenrek
de-bloat the proc structure by allocating notes with on the heap instead of embedding them in the proc structure. This saves around 640 bytes per process.
2022-08-17kernel: simplify notify() adding common popnote() functioncinap_lenrek
Handlin notes is common for all architectures except how the note has to be pushed on the user stack. This change adds a popnote() function that returns only the note string or nil if the process should not be notified (no notes or user notes hold off). Popnote() also handles common errors like notify during note handling or missing note handler and will suicide the process in that case.
2025-05-14kernel: get rid of Proc.kstackglenda
The kernel stack is now above the Proc structure, so the explicit kstack pointer can be eliminated.
2022-08-129: compute available kernel pages using sizeof(Proc*)Ori Bernstein
procs come from the dynamic pools, so we don't need to remove the memory used by possible procs from the total available.
2022-08-109/port: allow kiloprocs -- allocate procs lazilyOri Bernstein
Treallocate the small data structures around procs eagerly, but use malloc to allocate the large proc data structures when we need them, which allows us to scale to many more procs. There are still many scalability bottlenecks, so we only crank up the nproc limit by a little bit this time around, and crank it up more as we optimize more.
2022-05-02kernel: fix noteid change race condition from devproc while forking (thanks ↵cinap_lenrek
joe7) devproc allows changing the noteid of another process which opens a race condition in sysrfork(), when deciding to inherit the noteid of "up" to the child and calling pidalloc() later to take the reference, the noteid could have been changed and the childs noteid could have been freed already in the process. this bug can only happen when one writes the /proc/n/noteid file of a another process than your own that is in the process of forking. the noteid changing functionality of devproc seems questinable and seems to be only used by ape's setpgrid() implementation.
2021-10-16kernel: call freebroken() for kproc() when out of processescinap_lenrek
2021-10-16kernel: dont block allocating kstack for new processescinap_lenrek
Have newproc() fail returning nil if we can't allocate the kernel stack instead of locking up in smalloc().
2021-10-12kernel: return error from sysrfork instead of waiting and retryingcinap_lenrek
The old strategy of wait and retry doesnt seem to work very well as it keeps all the forking parents stuck waiting in the kernel worsening the situation. The idea with this change is to have rfork() return error quickly; and without whining; as most callers would just react with a sysfatal() which might be better for surviving this.
2020-12-22kernel: avoid palloc lock during mmurelease()cinap_lenrek
Previously, mmurelease() was always called with palloc spinlock held. This is unneccesary for some mmurelease() implementations as they wont release pages to the palloc pool. This change removes pagechainhead() and pagechaindone() and replaces them with just freepages() call, which aquires the palloc lock internally as needed. freepages() avoids holding the palloc lock while walking the linked list of pages, avoding some lock contention.
2020-12-21kernel: make addbroken() static, remove misleading Proc* argumentcinap_lenrek
2020-12-20kernel: handle tos and per process pcycle counters in port/cinap_lenrek
we might as well handle the per process cycle counter in the portable part instead of duplicating the code in every arch and have inconsistent implementations. we now have a portable kenter() and kexit() function, that is ment to be used in trap/syscall from user, which updates the counters. some kernels missed initializing Mach.cyclefreq.
2020-12-19kernel: remove Proc* argument from procsetuser() functioncinap_lenrek
2020-02-23kernel: avoid selecting the boot process in killbig()cinap_lenrek
2020-02-23kernel: fix multiple devproc bugs and pid reuse issuescinap_lenrek
devproc assumes that when we hold the Proc.debug qlock, the process will be prevented from exiting. but there is another race where the process has already exited and the Proc* slot gets reused. to solve this, on process creation we also have to acquire the debug qlock while initializing the fields of the process. this also means newproc() should only initialize fields *not* protected by the debug qlock. always acquire the Proc.debug qlock when changing strings in the proc structure to avoid doublefree on concurrent update. for changing the user string, we add a procsetuser() function that does this for auth.c and devcap. remove pgrpnote() from pgrp.c and replace by static postnotepg() in devproc. avoid the assumption that the Proc* entries returned by proctab() are continuous. fixed devproc permission issues: - make sure only eve can access /proc/trace - none should only be allowed to read its own /proc/n/text - move Proc.kp checks into procopen() pid reuse was not handled correctly, as we where only checking if a pid had a living process, but there still could be processes expecting a particular parentpid or noteid. this is now addressed with reference counted Pid structures which are organized in a hash table. read access to the hash table does not require locks which will be usefull for dtracy later.
2020-01-27kernel: restore old behaviour that kprocs have ther noteid == pidcinap_lenrek
2020-01-26kernel: implement portable userinit() and simplify process creationcinap_lenrek
replace machine specific userinit() by a portable implemntation that uses kproc() to create the first process. the initcode text is mapped using kmap(), so there is no need for machine specific tmpmap() functions. initcode stack preparation should be done in init0() where the stack is mapped and can be accessed directly. replacing the machine specific userinit() allows some big simplifications as sysrfork() and kproc() are now the only callers of newproc() and we can avoid initializing fields that we know are being initialized by these callers. rename autogenerated init.h and reboot.h headers. the initcode[] and rebootcode[] blobs are now in *.i files and hex generation was moved to portmkfile. the machine specific mkfile only needs to specify how to build rebootcode.out and initcode.out.
2020-01-11kernel: remove relics of CPU 'load balancing' policy in scheduler (thanks ↵cinap_lenrek
Robert Ransom) This code was deleted from Plan 9 before the 9front repo began. Proc.movetime was used by it, but has never been referenced in 9front.
2019-12-07pc: replace duplicated and broken mmu flush code in vunmap()cinap_lenrek
comparing m with MACHP() is wrong as m is a constant on 386. add procflushothers(), which flushes all processes except up using common procflushmmu() routine.
2019-12-07kernel: avoid useless mmu flushes, implement better wait condition for ↵cinap_lenrek
procflushmmu() procflushmmu() returns once all *OTHER* processors that had matching processes running on them flushed ther tlb/mmu state. the caller of procflush...() takes care of flushing "up" by calling flushmmu() later. if the current process matched, then that means m->flushmmu would be set, and hzclock() would call flushmmu() again. to avoid this, we now check up->newtlb in addition to m->flushmmu in hzclock() before calling flushmmu(). we also maintain information on which process on what processor to wait for locally, which helps making progress when multiple procflushmmu()'s are running concurrently. in addition, this makes the wait condition for procflushmmu() more sophisticated, by validating if the processor still runs the selected process and only if it matchatches, considers the MACHP(nm)->flushmmu flag.
2019-12-01kernel: improve diagnostics by reversing the roles of Proc.parentpid and ↵cinap_lenrek
Proc.parent for better system diagnostics, we *ALWAYS* want to record the parent pid of a user process, regardless of if the child will post a wait record on exit or not. for that, we reverse the roles of Proc.parent and Proc.parentpid so Proc.parentpid will always be set on rfork() and the Proc.parent pointer will point to the parent's Proc structure or is set to nil when no wait record should be posted on exit (RFNOWAIT flag). this means that we can get the pid of the original parent process from /proc, regardless of the the child having rforked with the RFNOWAIT flag. this improves the output of pstree(1) somewhat if the parent is still alive. note that theres no guarantee that the parent pid is still valid. the conditions are unchanged: a user process that will post wait record has: up->kp == 0 && up->parent != nil && up->parent->pid == up->parentpid the boot process is: up->kp == 0 && up->parent == nil && up->parentpid == 0 and kproc's have: up->kp != 0 && up->parent == nil && up->parentpid == 0
2019-09-08kernel: clear FPillegal in pexit() and before pprint()cinap_lenrek
pexit() and pprint() can get called outside of a syscall (from procctl()) with a process that is in active note handling and require floating point in the kernel on amd64 for aesni (devtls).
2019-05-01kernel: insert memory barrier in the scheduler before setting up->mach = nilcinap_lenrek
we have to ensure that all stores saving the process state have completed before setting up->mach = nil in the scheduler. otherwise, another cpu could observe up->mach == nil while the stores such as the processes p->sched label have not finnished.
2018-09-18kernel: fix livelock in rebalance (thanks Richard Miller)cinap_lenrek
Once a second rebalance() is called on cpu0 to adjust priorities, so cpu-bound processes won't lock others out. However it was only adjusting processes which were running on cpu0. This was observed to lead to livelock, eg when a higher-priority process spin-waits for a lock held by a lower priority one.
2017-06-20kernel: add support for sticky segments (cached, preallocated, never paged)cinap_lenrek
2017-06-12kernel: reset nwatchpt in pexitaiju
2017-06-12kernel: add support for hardware watchpointsaiju
2017-06-03kernel: make statistics counters skipscheds and preempts unsignedcinap_lenrek
2017-06-02kernel: don't preempt pager during fscache reclaimcinap_lenrek
the fscache image is the main source for pages once the page freelist got exhausted, so delay scheduling until they release the fscache lock.
2017-03-29kernel: fix twakeup()/timerdel() race conditioncinap_lenrek
timerdel() did not make sure that the timer function is not active (on another cpu). just acquiering the Timer lock in the timer function only blocks the caller of timerdel()/timeradd() but not the other way arround (on a multiprocessor). this changes the timer code to track activity of the timer function, having timerdel() wait until the timer has finished executing.
2016-09-08kernel: fix type for utime/stime in pexit(), fix debug format stringscinap_lenrek
2016-09-08kernel: always do unsigned subtractions for m->ticks delta for updatecpu() ↵cinap_lenrek
and rebalance(), handle ticks wrap arround in hzsched()
2016-03-29kernel: fix procflushmmu()cinap_lenrek
fix bug introduced in previous change for zynq, broke procflushseg() function only flushing the first proc matching the segment.
2016-03-28kernel: print pid as %lud instead %lux (in tsleep() debug print)cinap_lenrek
2016-03-27zynq: introduce SG_FAULT to prevent access to AXI segment while PL is not readycinap_lenrek
access to the axi segment hangs the machine when the fpga is not programmed yet. to prevent access, we introduce a new SG_FAULT flag, that when set on the Segment.type or Physseg.attr, causes the fault handler to immidiately return with an error (as if the segment would not be mapped). during programming, we temporarily set the SG_FAULT flag on the axi physseg, flush all processes tlb's that have the segment mapped and when programming is done, we clear the flag again.
2016-03-26kernel: fix tsleep()/twakeup()/tsemacquire() racecinap_lenrek
tsleep() used to cancel the timer with: if(up->tt != nil) timerdel(up); which still can result in twakeup() to fire after tsleep() returns (because we set Timer.tt to nil *before* we call the tfn). in most cases, this is not an issue as the Rendez* usually is just &up->sleep, but when it is dynamically allocated or on the stack like in tsemacquire(), twakeup() will call wakeup() on a potentially garbage Rendez structure! to fix the race, we execute the wakup() with the Timer lock held, and set p->trend to nil only after we called wakeup(). that way, the timerdel(); which unconditionally locks the Timer; can act as a proper barrier and use up->trend == nil as the condition if the timer has already fired.
2016-01-07format pointer subtraction results with %zd instead of %ld (for long -> ↵cinap_lenrek
intptr on amd64)
2015-08-25fix fuckupglenda
2015-08-25import E script from bell labsmischief
2015-06-18kernel: do not inherit Proc.dot (current working directory) in kproc()cinap_lenrek
making sure to close the dot in every kproc appears repetitive, so instead stop inheriting the dot in kproc() as this is usually never what you wanted in the first place.
2015-06-12kernel: fix accounttime() for HZ >= 1000cinap_lenrek
"milli-CPU's" is too low resolution for the decaying load average calculation when HZ >= 1000.
2015-04-16kernel: leave shared, physical and fixed segments alone in killbig()cinap_lenrek
2014-11-09kernel: remove implicit Proc* argument from procctl()cinap_lenrek
procctl() is always called with up and it would not work correctly if passed a different process, so remove the Proc* argument and use up directly.
2014-08-17kernel: make noswap flag exclude processes from killbig() if not eve, reset ↵cinap_lenrek
noswap flag on exec
2014-07-14devproc: fix proccrlmemio bugscinap_lenrek
dont kill the calling process when demand load fails if fixfault() is called from devproc. this happens when you delete the binary of a running process and try to debug the process accessing uncached pages thru /proc/$pid/mem file. fixes to procctlmemio(): - fix missed unlock as txt2data() can error - make sure the segment isnt freed by taking a reference (under p->seglock) - access the page with segment locked (see comment) - get rid of the segment stealer lock other stuff: - move txt2data() and data2txt() to segment.c - add procpagecount() function - make return type mcounseg() to ulong
2014-06-23kernel: more proc.c cleanupcinap_lenrek
2014-06-23kernel: make use of nil and 0 consistent in proc.ccinap_lenrek
always explicitely compare with nil if pointer. sorry for the noise. :(