aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/pkg.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-07-09 09:45:43 +0900
committerOphestra <cat@gensokyo.uk>2026-07-09 09:45:43 +0900
commit6cfd8fb93484b5683f4a59f84b5bf5b0dde208a2 (patch)
tree9ff4b57607fc965963746378184b834d4fbdfd58 /internal/pkg/pkg.go
parent2f1534853a187018b94754e5ae2f009d7c2ae347 (diff)
internal/pkg: loadavg target in container environment
This exposes preferred loadavg target to the container initial process. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/pkg.go')
-rw-r--r--internal/pkg/pkg.go30
1 files changed, 20 insertions, 10 deletions
diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go
index ea493d39..99a54462 100644
--- a/internal/pkg/pkg.go
+++ b/internal/pkg/pkg.go
@@ -281,6 +281,10 @@ func (c *common) GetMessage() message.Msg { return c.cache.msg }
// value must not affect cure outcome.
func (c *common) GetJobs() int { return c.cache.attr.Jobs }
+// GetLoad returns the preferred load average target, when applicable. Its
+// value must not affect cure outcome.
+func (c *common) GetLoad() int { return c.cache.attr.Load }
+
// GetWorkDir returns a pathname to a directory which [Artifact] is expected to
// write its output to. This is not the final resting place of the [Artifact]
// and this pathname should not be directly referred to in the final contents.
@@ -2684,6 +2688,8 @@ type CacheAttr struct {
Flags int
// Preferred job count, when applicable.
Jobs int
+ // Preferred loadavg target, when applicable.
+ Load int
// Omit the [lockedfile] lock.
skipLock bool
@@ -2716,15 +2722,19 @@ func Open(
panic("attempting to open cache with incomplete variant setup")
}
- if attr == nil {
- attr = new(CacheAttr)
+ var a CacheAttr
+ if attr != nil {
+ a = *attr
}
- if attr.Cures < 1 {
- attr.Cures = runtime.NumCPU()
+ if a.Cures < 1 {
+ a.Cures = runtime.NumCPU()
+ }
+ if a.Jobs < 1 {
+ a.Jobs = runtime.NumCPU()
}
- if attr.Jobs < 1 {
- attr.Jobs = runtime.NumCPU()
+ if a.Load < 1 {
+ a.Load = runtime.NumCPU() + 2
}
for _, name := range []string{
@@ -2746,8 +2756,8 @@ func Open(
c := Cache{
parent: ctx,
- cures: make(chan struct{}, attr.Cures),
- attr: *attr,
+ cures: make(chan struct{}, a.Cures),
+ attr: a,
msg: msg,
base: base,
@@ -2764,7 +2774,7 @@ func Open(
}
c.toplevel.Store(newToplevel(ctx))
- if !attr.skipLock || !testing.Testing() {
+ if !a.skipLock || !testing.Testing() {
if unlock, err := lockedfile.MutexAt(
base.Append(fileLock).String(),
).Lock(); err != nil {
@@ -2825,7 +2835,7 @@ func Open(
}
} else if s := string(p); s == "" {
if extension != "" {
- if attr.Flags&CPromoteVariant == 0 {
+ if a.Flags&CPromoteVariant == 0 {
c.unlock()
return nil, ErrWouldPromote
}