46 Commits

Author SHA1 Message Date
Ayush Ranjan d4861911c2 Make atomicbitops.Bool savable.
Earlier the atomicbitops_state_autogen.go was not being built because it had
an impossible build condition: `(amd64 || arm64) && !amd64 && !arm64`.

This is a known deficiency in go_stateify tool. This was solved via having
two identical files like 32b_32bit.go and 32b_64bit.go. Just piggyback this.

This changes also enhances `atomicbitops.Bool` in the following ways:
- Added RacyLoad(), RacyStore() and CompareAndSwap() for Bool to bring it up to
  speed with the other types.
- Delegated the actual atomic operations work to the underlying Uint32.
- Cleaned up code with b32(); similar to what sync/atomic.Bool does.

PiperOrigin-RevId: 597607982
2024-01-11 11:24:32 -08:00
Etienne Perot cb0481301f atomicbitops: Add atomic float64.
This adds a new atomic type, `atomicbitops.Float64`, which has similar
operations as `atomicbitops.Uint64`. It actually uses `atomicbitops.Uint64`
for storing its bits.

`atomicbitops.Float64` supports `Swap`, `CompareAndSwap`, and `Add`
operations.

This is useful in gVisor's metric library for keeping track of the
sum-of-squared-deviation statistic of distribution metrics.

PiperOrigin-RevId: 537127647
2023-06-01 14:24:59 -07:00
Adin Scannell 5ba34bd1a5 Add explicit NOFRAME annotation in assembly functions.
For all trivial and zero frame-sized functions, we now require an explicit
NOFRAME annotation as the heuristic has changed. See go.dev/cl/466316.

Most of these functions do not  *require* NOFRAME, but this change encodes
the existing behavior in order to avoid accidental bugs or regressions.

PiperOrigin-RevId: 513946210
2023-03-04 00:53:20 -08:00
Adin Scannell 1ceb814544 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Adin Scannell be86ca7d22 Fix assembly declarations.
PiperOrigin-RevId: 511648708
2023-02-22 18:14:26 -08:00
Nicolas Lacasse 4f326de476 Make nic.spoofing and nic.promiscuous atomic Bools to avoid lock contention.
Also add atomicbitops.Bool which is just a Uint32, but behaves as a boolean.

PiperOrigin-RevId: 495103870
2022-12-13 13:08:11 -08:00
gVisor bot dac6639a3b Merge pull request #7850 from bradfitz:bradfitz/cpuid
PiperOrigin-RevId: 464643287
2022-08-01 15:54:39 -07:00
Brad Fitzpatrick 801f45ab4b atomicbitops, cpuid: fix warnings, lack of atomics on macOS
Updates google/gvisor#7849
2022-07-31 19:26:54 -07:00
Ayush Ranjan f6ed4523dc Reformat codebase.
PiperOrigin-RevId: 449358041
2022-05-17 17:48:35 -07:00
gVisor bot 3b11bfe105 Merge pull request #7391 from zhlhahaha:2477
PiperOrigin-RevId: 446793644
2022-05-05 13:07:01 -07:00
Kevin Krakauer 7124367b82 prohibit direct use of sync/atomic (u)int32 functions
Also adds the "// +checkalignedignore" escape hatch for packages to opt out of
checking.

See cl/439349432 for justification (https://github.com/google/gvisor/pull/7376).

PiperOrigin-RevId: 444918125
2022-04-27 11:25:14 -07:00
howard zhang 1cef45605e Arm64 atomic: add LSE atomics instructions to arm64
benchmark for the atomics instructions:
Without LSE instructions:
BenchmarkAndUint32-80                           138205774                8.562 ns/op
BenchmarkAndUint64-80                           139365404                8.571 ns/op
BenchmarkAndUint32Parallel-80                   16887577               259.6 ns/op
BenchmarkAndUint64Parallel-80                    6202482               281.2 ns/op
BenchmarkOrUint32-80                            138791865                8.592 ns/op
BenchmarkOrUint64-80                            138424888                8.670 ns/op
BenchmarkOrUint32Parallel-80                    15080332               175.1 ns/op
BenchmarkOrUint64Parallel-80                     8891142               262.2 ns/op
BenchmarkXorUint32-80                           139146337                8.611 ns/op
BenchmarkXorUint64-80                           138612325                8.627 ns/op
BenchmarkXorUint32Parallel-80                    3651159               548.5 ns/op
BenchmarkXorUint64Parallel-80                   17135235               350.2 ns/op
BenchmarkCompareAndSwapUint32-80                11712571                95.49 ns/op
BenchmarkCompareAndSwapUint64-80                12229885                87.32 ns/op
BenchmarkCompareAndSwapUint32Parallel-80        11853363               115.6 ns/op
BenchmarkCompareAndSwapUint64Parallel-80        15574476                87.91 ns/op

With LSE instructions:
BenchmarkAndUint32-80                           172129803                6.933 ns/op
BenchmarkAndUint64-80                           170516512                6.993 ns/op
BenchmarkAndUint32Parallel-80                   60089396                20.14 ns/op
BenchmarkAndUint64Parallel-80                   59266794                20.01 ns/op
BenchmarkOrUint32-80                            174805162                6.835 ns/op
BenchmarkOrUint64-80                            174935716                6.836 ns/op
BenchmarkOrUint32Parallel-80                    60084607                19.89 ns/op
BenchmarkOrUint64Parallel-80                    51555650                19.99 ns/op
BenchmarkXorUint32-80                           170525718                6.835 ns/op
BenchmarkXorUint64-80                           175269829                6.842 ns/op
BenchmarkXorUint32Parallel-80                   60005954                20.15 ns/op
BenchmarkXorUint64Parallel-80                   51590584                19.95 ns/op
BenchmarkCompareAndSwapUint32-80                27096822                40.69 ns/op
BenchmarkCompareAndSwapUint64-80                27516450                39.02 ns/op
BenchmarkCompareAndSwapUint32Parallel-80        27194458                40.69 ns/op
BenchmarkCompareAndSwapUint64Parallel-80        27614142                39.25 ns/op

Signed-off-by: howard zhang <howard.zhang@arm.com>
2022-04-20 14:57:40 +08:00
Kevin Krakauer ec44093c97 introduce atomicbitops 32-bit types
Part of a series of changes that will end with prohibiting use of sync/atomic
(u)int32 functions. See cl/440484071 for more details.

PiperOrigin-RevId: 442673296
2022-04-18 17:41:53 -07:00
Kevin Krakauer 370672e989 prohibit direct use of sync/atomic (u)int64 functions
All atomic 64 bit ints are changed to atomicbitops.(Ui|I)nt64. A nogo checker
enforces that sync/atomic 64 bit functions are not called.

For reviewers: the interesting changes are in the atomicbitops and checkaligned
packages.

Why do this?
- It is very easy to accidentally use atomic values without sync/atomic funcs.
- We have checkatomics, but this is optional and is forgotten in several places.
  - Using a type+checker to enforce this seems less error prone and simpler.
- We get NoCopy protection.
- Use of 64 bit atomics can break 32 bit builds. We have types to handle this
  without any runtime cost, so we might as well use them.

PiperOrigin-RevId: 440473398
2022-04-08 16:06:26 -07:00
Brad Fitzpatrick 2aa474e748 pkg/atomicbitops: support 32-bit GOARCH value "mipsle"
mips was supported, but mipsle had been forgotten.

Fixes google/gvisor#6804
2021-11-01 08:22:07 -07:00
Koichi Shiraishi 7570685222 No split to assembly and noasm functions on atomicbitops package
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
2021-10-04 19:22:09 +09:00
gVisor bot 21b38e8bcc Merge pull request #6182 from zchee:atomicbitops-bp
PiperOrigin-RevId: 397432940
2021-09-17 17:48:24 -07:00
Kevin Krakauer 345eb4a666 fix typo
PiperOrigin-RevId: 390463819
2021-08-12 14:43:45 -07:00
Koichi Shiraishi ec8bdfae7f Use BX instead of BP at AX second op
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
2021-08-12 06:28:30 +09:00
Koichi Shiraishi f13a9e2c13 Use BX insted of BP
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
2021-08-12 06:22:36 +09:00
Andrei Vagin 376e890432 Reduce overhead of AlignedAtomic types
AlignedAtomicUint64 is 15 bytes and it takes 16 bytes in structures.  On
32-bit systems, variables and structure fields is guaranteed to be
32-bit aligned and this means that we need only 12 bytes to find 8
contiguous bytes.
2021-08-04 21:17:21 -07:00
Jamie Liu 1ad3822200 Add go:build directives as required by Go 1.17's gofmt.
PiperOrigin-RevId: 385894869
2021-07-20 16:28:45 -07:00
Koichi Shiraishi d00ef10456 Fix frame pointer is clobbered before saving vet issue on BP register
BP should be callee-save. It will be saved automatically if there is nonzero frame size.

$ go vet -framepointer ./pkg/atomicbitops
pkg/atomicbitops/atomicbitops_amd64.s:27:1: frame pointer is clobbered before saving
pkg/atomicbitops/atomicbitops_amd64.s:34:1: frame pointer is clobbered before saving
pkg/atomicbitops/atomicbitops_amd64.s:50:1: frame pointer is clobbered before saving
pkg/atomicbitops/atomicbitops_amd64.s:57:1: frame pointer is clobbered before saving
pkg/atomicbitops/atomicbitops_amd64.s:64:1: frame pointer is clobbered before saving

Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
2021-06-14 11:09:14 +09:00
Kevin Krakauer d5f69e0dec Use an exhaustive list of architectures 2021-05-12 10:26:21 -07:00
Kevin Krakauer b3d42a6ce7 enable building //pkg/tcpip on 32-bit MIPS
N.B. we don't explicitly support MIPS, but there's no reason it
shouldn't work.
2021-05-12 10:14:56 -07:00