Making Code A Hundred Times Slower With False Sharing

The cache hierarchy of the 2008 Intel Nehalem x86 architecture. (Source: Intel)
The cache hierarchy of the 2008 Intel Nehalem x86 architecture. (Source: Intel)

Writing good, performant code depends strongly on an understanding of the underlying hardware. This is especially the case in scenarios like those involving embarrassingly parallel processing, which at first glance ought to be a cakewalk. With multiple threads doing their own thing without having to nag the other threads about anything it seems highly doubtful that even a novice could screw this up. Yet as [Keifer] details in a recent video on so-called false sharing, this is actually very easy, for a variety of reasons.

With a multi-core and/or multi-processor system each core has its own local cache that contains a reflection of the current values in system RAM. If any core modifies its cached data, this automatically invalidates the other cache lines, resulting a cache miss for those cores and forcing a refresh from system RAM. This is the case even if the accessed data isn’t one that another core was going to use, with an obvious impact on performance.

The worst case scenario as detailed and demonstrated using the Google Benchmark sample projects, involves a shared global data structure, with a recorded hundred times reduction in performance. Also noticeable is the impact on scaling performance, with the cache misses becoming more severe with more threads running.

A less obvious cause of performance loss here is due to memory alignment and how data fits in the cache lines. Making sure that your data is aligned in e.g. data structures can prevent more unwanted cache invalidation events. With most applications being multi-threaded these days, it’s a good thing to not only know how to diagnose false sharing issues, but also how to prevent them.

Continue reading “Making Code A Hundred Times Slower With False Sharing”

Dad Makes Kid’s Balance Bike Into Electric Snow Trike Like A Boss

The balance bikes toddlers are rocking these days look like great fun, but not so great in the snow. Rather than see his kid’s favourite toy relegated to shed until spring, [John Boss] added electric power, and an extra wheel to make one fun-looking snow trike. Like a boss, you might say.

Physically, the trike is a delta configuration: two rear wheels and one front, though as you can see the front wheel has been turned into a ski. That’s not the most stable configuration, but by shifting the foot pegs to the front wheel and keeping the electronics down low, [John] is able to maintain a safe center of gravity. He’s also limiting the throttle so kiddo can’t go dangerously fast– indeed, the throttle control is in the rear electronics component. The kid just has a big green “go” button.

Bit-banging the throttle, combined with the weight of the kiddo up front, creates a strong tendency towards wheel-spin, but [John] fixes that with a some cleverly printed TPU paddles zip-tied to the harbor-freight wheels and tires he’s hacked into use. Those wheels are fixed to a solid axle that’s mounted to flat plate [John] had made up to attach to the bike frame. It’s all surprisingly solid, given that [John] is able to demonstrate the safety factor by going for a spin of his own. We would have done the same.

We particularly like the use of a tool battery for hot-swappable power. This isn’t the first time we’ve seen a kid’s toy get the tool battery treatment, but you aren’t limited to mobile uses. We’ve seen the ubiquitous 18V power packs in everything from fume extractors to a portable powerpack that can even charge a Tesla.

Continue reading “Dad Makes Kid’s Balance Bike Into Electric Snow Trike Like A Boss”

A New Life For An Old Amplifier

An audio amplifier was once a fairly simple analogue device, but in recent decades a typical home entertainment amplifier will have expanded to include many digital functions. When these break they are often proprietary and not easy to repair, as was the case with a broken Pioneer surround-sound device given to [Boz]. It sat on the shelf for a few years until he had the idea of a jukebox for his ripped CDs, and his returning it to life with a new main board is something to behold.

Internally it’s a surprisingly modular design, meaning that the front panel with its VFD display and driver were intact and working, as were the class AB amplifier and its power supply. He had the service manual so reverse engineering was straightforward, thus out came the main board in favor of a replacement. He took the original connectors and a few other components, then designed a PCB to take them and a Raspberry Pi Pico and DAC. With appropriate MMBASIC firmware it looks as though it was originally made this way, a sense heightened by a look at the motherboard inside (ignoring a couple of bodges).

We like seeing projects like this one which revive broken devices, and this one is particularly special quality wise. We’re more used to seeing it with gaming hardware though.

Genetic Therapy Aims To Bring Hearing To Those Born Deaf

For those born with certain types of congenital deafness, the cochlear implant has been a positive and enabling technology. It uses electronics to step in as a replacement for the biological ear that doesn’t quite function properly, and provides a useful, if imperfect, sense of hearing to its users.

New research has promised another potential solution for some sufferers of congenital deafness. Instead of a supportive device, a gene therapy is used to enable the biological ear to function more as it should. The result is that patients get their sense of hearing, not from a prosthetic, but from their own ears themselves.

Continue reading “Genetic Therapy Aims To Bring Hearing To Those Born Deaf”

ESP32-P4 Powers Retro Handheld After A Transplant

The ESP32-P4 is the new hotness on the microcontroller market. With RISC-V architecture and two cores running 400 MHz, to ears of a certain vintage it sounds more like the heart of a Unix workstation than a traditional MCU. Time’s a funny thing like that. [DynaMight] was looking for an excuse to play with this powerful new system on a chip, so put together what he calls the GB300-P4: a commercial handheld game console with an Expressif brain transplant.

Older ESP32 chips weren’t quite up to 16-bit emulation, but that hadn’t stopped people trying; the RetroGo project by [ducalex] already has an SNES and Genesis/Mega Drive emulation mode, along with all the 8-bit you could ask for. But the higher-tech consoles can run a bit slow in emulation on other ESP32 chips. [DynaMight] wanted to see if the P4 performed better, and to no ones surprise, it did.

If the build quality on this handheld looks suspiciously professional, that’s because it is: [DynaMight] started with a GB300, a commercial emulator platform. Since the ESP32-P4 is replacing a MIPS chip clocked at 914 MHz in the original — which sounds even more like the heart of a Unix workstation, come to think of it — the machine probably doesn’t have better performance than it did from factory unless its code was terribly un-optimized. In this case, performance was not the point. The point was to have a handheld running RetroGo on this specific chip, which the project has evidently accomplished with flying colours. If you’ve got a GB300 you’d rather put an “Expressif Inside” sticker on, the project is on github. Otherwise you can check out the demo video below. (DOOM starts at 1:29, because of course it runs DOOM.)

The last P4 project we featured was a Quadra emulator; we expect to see a lot of projects with this chip in the new year, and they’re not all going to be retrocomputer-related, we’re sure. If you’re cooking up something using the new ESP32, or know someone who is, you know what to do.

Continue reading “ESP32-P4 Powers Retro Handheld After A Transplant”

Clone Wars: IBM Edition

If you search the Internet for “Clone Wars,” you’ll get a lot of Star Wars-related pages. But the original Clone Wars took place a long time ago in a galaxy much nearer to ours, and it has a lot to do with the computer you are probably using right now to read this. (Well, unless it is a Mac, something ARM-based, or an old retro-rig. I did say probably!)

IBM is a name that, for many years, was synonymous with computers, especially big mainframe computers. However, it didn’t start out that way. IBM originally made mechanical calculators and tabulating machines. That changed in 1952 with the IBM 701, IBM’s first computer that you’d recognize as a computer.

If you weren’t there, it is hard to understand how IBM dominated the computer market in the 1960s and 1970s. Sure, there were others like Univac, Honeywell, and Burroughs. But especially in the United States, IBM was the biggest fish in the pond. At one point, the computer market’s estimated worth was a bit more than $11 billion, and IBM’s five biggest competitors accounted for about $2 billion, with almost all of the rest going to IBM.

So it was somewhat surprising that IBM didn’t roll out the personal computer first, or at least very early. Even companies that made “small” computers for the day, like Digital Equipment Corporation or Data General, weren’t really expecting the truly personal computer. That push came from companies no one had heard of at the time, like MITS, SWTP, IMSAI, and Commodore. Continue reading “Clone Wars: IBM Edition”