mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-23 12:16:38 +00:00
acc333c40b
When GTS is running in a container runtime which has configured CPU or memory limits or under an init system that uses cgroups to impose CPU and memory limits the values the Go runtime sees for GOMAXPROCS and GOMEMLIMIT are still based on the host resources, not the cgroup. At least for the throttling middlewares which use GOMAXPROCS to configure their queue size, this can result in GTS running with values too big compared to the resources that will actuall be available to it. This introduces 2 dependencies which can pick up resource contraints from the current cgroup and tune the Go runtime accordingly. This should result in the different queues being appropriately sized and in general more predictable performance. These dependencies are a no-op on non-Linux systems or if running in a cgroup that doesn't set a limit on CPU or memory. The automatic tuning of GOMEMLIMIT can be disabled by either explicitly setting GOMEMLIMIT yourself or by setting AUTOMEMLIMIT=off. The automatic tuning of GOMAXPROCS can similarly be counteracted by setting GOMAXPROCS yourself.
110 lines
2.7 KiB
Go
110 lines
2.7 KiB
Go
package asm
|
|
|
|
//go:generate stringer -output jump_string.go -type=JumpOp
|
|
|
|
// JumpOp affect control flow.
|
|
//
|
|
// msb lsb
|
|
// +----+-+---+
|
|
// |OP |s|cls|
|
|
// +----+-+---+
|
|
type JumpOp uint8
|
|
|
|
const jumpMask OpCode = aluMask
|
|
|
|
const (
|
|
// InvalidJumpOp is returned by getters when invoked
|
|
// on non branch OpCodes
|
|
InvalidJumpOp JumpOp = 0xff
|
|
// Ja jumps by offset unconditionally
|
|
Ja JumpOp = 0x00
|
|
// JEq jumps by offset if r == imm
|
|
JEq JumpOp = 0x10
|
|
// JGT jumps by offset if r > imm
|
|
JGT JumpOp = 0x20
|
|
// JGE jumps by offset if r >= imm
|
|
JGE JumpOp = 0x30
|
|
// JSet jumps by offset if r & imm
|
|
JSet JumpOp = 0x40
|
|
// JNE jumps by offset if r != imm
|
|
JNE JumpOp = 0x50
|
|
// JSGT jumps by offset if signed r > signed imm
|
|
JSGT JumpOp = 0x60
|
|
// JSGE jumps by offset if signed r >= signed imm
|
|
JSGE JumpOp = 0x70
|
|
// Call builtin or user defined function from imm
|
|
Call JumpOp = 0x80
|
|
// Exit ends execution, with value in r0
|
|
Exit JumpOp = 0x90
|
|
// JLT jumps by offset if r < imm
|
|
JLT JumpOp = 0xa0
|
|
// JLE jumps by offset if r <= imm
|
|
JLE JumpOp = 0xb0
|
|
// JSLT jumps by offset if signed r < signed imm
|
|
JSLT JumpOp = 0xc0
|
|
// JSLE jumps by offset if signed r <= signed imm
|
|
JSLE JumpOp = 0xd0
|
|
)
|
|
|
|
// Return emits an exit instruction.
|
|
//
|
|
// Requires a return value in R0.
|
|
func Return() Instruction {
|
|
return Instruction{
|
|
OpCode: OpCode(JumpClass).SetJumpOp(Exit),
|
|
}
|
|
}
|
|
|
|
// Op returns the OpCode for a given jump source.
|
|
func (op JumpOp) Op(source Source) OpCode {
|
|
return OpCode(JumpClass).SetJumpOp(op).SetSource(source)
|
|
}
|
|
|
|
// Imm compares dst to value, and adjusts PC by offset if the condition is fulfilled.
|
|
func (op JumpOp) Imm(dst Register, value int32, label string) Instruction {
|
|
if op == Exit || op == Call || op == Ja {
|
|
return Instruction{OpCode: InvalidOpCode}
|
|
}
|
|
|
|
return Instruction{
|
|
OpCode: OpCode(JumpClass).SetJumpOp(op).SetSource(ImmSource),
|
|
Dst: dst,
|
|
Offset: -1,
|
|
Constant: int64(value),
|
|
Reference: label,
|
|
}
|
|
}
|
|
|
|
// Reg compares dst to src, and adjusts PC by offset if the condition is fulfilled.
|
|
func (op JumpOp) Reg(dst, src Register, label string) Instruction {
|
|
if op == Exit || op == Call || op == Ja {
|
|
return Instruction{OpCode: InvalidOpCode}
|
|
}
|
|
|
|
return Instruction{
|
|
OpCode: OpCode(JumpClass).SetJumpOp(op).SetSource(RegSource),
|
|
Dst: dst,
|
|
Src: src,
|
|
Offset: -1,
|
|
Reference: label,
|
|
}
|
|
}
|
|
|
|
// Label adjusts PC to the address of the label.
|
|
func (op JumpOp) Label(label string) Instruction {
|
|
if op == Call {
|
|
return Instruction{
|
|
OpCode: OpCode(JumpClass).SetJumpOp(Call),
|
|
Src: PseudoCall,
|
|
Constant: -1,
|
|
Reference: label,
|
|
}
|
|
}
|
|
|
|
return Instruction{
|
|
OpCode: OpCode(JumpClass).SetJumpOp(op),
|
|
Offset: -1,
|
|
Reference: label,
|
|
}
|
|
}
|