main 6af0a61

cpu.go RawHistoryFolder

1package system
2
3import "errors"
4
5// CPUVendor represents the CPU vendor
6type CPUVendor int
7
8const (
9	// CPUVendorUnknown represents an unknown CPU vendor
10	CPUVendorUnknown CPUVendor = iota
11
12	// CPUVendorIntel represents Intel CPUs
13	CPUVendorIntel
14
15	// CPUVendorAMD represents AMD CPUs
16	CPUVendorAMD
17
18	// CPUVendorARM represents ARM CPUs
19	CPUVendorARM
20)
21
22// String returns human-readable vendor name
23func (v CPUVendor) String() string {
24	switch v {
25	case CPUVendorIntel:
26		return "Intel"
27	case CPUVendorAMD:
28		return "AMD"
29	case CPUVendorARM:
30		return "ARM"
31	default:
32		return "Unknown"
33	}
34}
35
36// Microcode represents CPU microcode package
37type Microcode int
38
39const (
40	// MicrocodeNone means no microcode updates
41	MicrocodeNone Microcode = iota
42
43	// MicrocodeIntel for Intel CPUs
44	MicrocodeIntel
45
46	// MicrocodeAMD for AMD CPUs
47	MicrocodeAMD
48)
49
50// String returns microcode package name
51func (m Microcode) String() string {
52	switch m {
53	case MicrocodeIntel:
54		return "intel-ucode"
55	case MicrocodeAMD:
56		return "amd-ucode"
57	default:
58		return ""
59	}
60}
61
62// CPUInfo is an immutable value object representing CPU information
63// It includes vendor, model, and microcode availability
64type CPUInfo struct {
65	vendor    CPUVendor
66	model     string // CPU model name
67	microcode Microcode
68}
69
70// NewCPUInfo creates a new CPUInfo value object
71func NewCPUInfo(vendor CPUVendor, model string, microcode Microcode) (*CPUInfo, error) {
72	if model == "" {
73		return nil, errors.New("CPU model cannot be empty")
74	}
75
76	if len(model) > 128 {
77		return nil, errors.New("CPU model name too long")
78	}
79
80	// Validate microcode matches vendor
81	if vendor == CPUVendorIntel && microcode == MicrocodeAMD {
82		return nil, errors.New("AMD microcode cannot be used with Intel CPU")
83	}
84
85	if vendor == CPUVendorAMD && microcode == MicrocodeIntel {
86		return nil, errors.New("intel microcode cannot be used with AMD CPU")
87	}
88
89	return &CPUInfo{
90		vendor:    vendor,
91		model:     model,
92		microcode: microcode,
93	}, nil
94}
95
96// Vendor returns the CPU vendor
97func (c *CPUInfo) Vendor() CPUVendor {
98	return c.vendor
99}
100
101// Model returns the CPU model name
102func (c *CPUInfo) Model() string {
103	return c.model
104}
105
106// Microcode returns the CPU microcode package
107func (c *CPUInfo) Microcode() Microcode {
108	return c.microcode
109}
110
111// RequiresMicrocode returns true if this CPU needs microcode updates
112func (c *CPUInfo) RequiresMicrocode() bool {
113	return c.microcode != MicrocodeNone
114}
115
116// String returns human-readable representation
117func (c *CPUInfo) String() string {
118	return "CPUInfo(vendor=" + c.vendor.String() +
119		", model=" + c.model +
120		", microcode=" + c.microcode.String() + ")"
121}
122
123// Equals checks if two CPUInfo objects are equal
124func (c *CPUInfo) Equals(other *CPUInfo) bool {
125	if other == nil {
126		return false
127	}
128	return c.vendor == other.vendor &&
129		c.model == other.model &&
130		c.microcode == other.microcode
131}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 0

    ↑↓ moveenter openesc close