Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

Allow dynamic modification of trace flags
The current RTS does not permit dynamic modification of the trace flags. The trace flags in `RtsFlags.TraceFlags` are initially set when parsing the RTS options, but `Trace.c` keeps a cache of trace flags in the `TRACE_*` globals, which are mostly hidden (`TRACE_user` is exposed by accident). @alt-romes and I did a bit of digging and found that there does not appear to be a genuine reason for caching the trace flags. The first global `TRACE_sched` was introduced as a static global to cache the following computation... ```c // -Ds turns on scheduler tracing too TRACE_sched = RtsFlags.TraceFlags.scheduler || RtsFlags.DebugFlags.scheduler; ``` ...and the other trace flags seem to have just followed this pattern as they were introduced. I'm considering two possible designs: ## Modify `RtsFlags.TraceFlags` and remove trace flag cache. This design uses `RtsFlags.TraceFlags` as the only source of truth, allows it to be modified, and does not require any changes to `Rts.h`. The core idea: If `-Ds` is passed, this is taken to _directly_ imply `-ls`, i.e., while parsing the arguments, if `-Ds` is encountered, both `RtsFlags.TraceFlags.scheduler` and `RtsFlags.DebugFlags.scheduler` are set to true. Similar for the other trace and debug flags. This removes the need for the cache altogether. (This requires some fidgeting for `TRACE_cap`, which doesn't correspond to an RTS option.) The user of `Rts.h` is free to modify the `RtsFlags.TraceFlags` global. Caveats: The members of `RtsFlags.TraceFlags` are boolean flags and are not protected by a mutex, because they aren't necessarily designed to be modified at after RTS initialisation. Therefore, allowing the user to modify them _will_ result in races. However, these probably don't matter too much, as long as we maintain the internal invariant that trace functions in the RTS (1) never cache the value of the `RtsFlags.TraceFlags` globals for longer than a single `traceSomeEvent` call and (2) decide whether or not to trace each event as a whole, rather than starting/stopping a trace midway through. ## Use trace flag cache and do NOT modify `RtsFlags.TraceFlags`. This design uses a separate trace flag cache, never updates `RtsFlags.TraceFlags`, and exposes new functions from `Rts.h` that enable the user to modify the cache. The core idea: Expose a new function from the RTS that enables the user to modify the `TRACE_*` globals. For instance, ``` enum RuntimeTraceFlag { .. } bool getRuntimeTraceFlag(enum RuntimeTraceFlag flag); void setRuntimeTraceFlag(enum RuntimeTraceFlag flag, bool value); ``` Caveats: This requires us to maintain the internal invariant that trace functions _only_ read the trace flag cache, never the `RtsFlags.TraceFlags` globals. This also introduces some awkwardness where the base `getTraceFlags` function only returns the initial state, not the runtime state, unless we change the behaviour of that function accordingly. ## Atomic trace flags We could use the GNU atomics (or, with some more effort, the C11 atomics) for the trace flags, either in `RtsFlags.TraceFlags` (with a major breaking change to `Rts.h`) or in the cache (handled internally in `getRuntimeTraceFlag` and `setRuntimeTraceFlag`). However, these values are used _a lot_, so the performance overhead would probably enormous, just to avoid a pretty benign race condition.
issue