Welcome, Guest. Please login or register.

Author Topic: Why is SMT (multicore) support hard for Amiga OS?  (Read 11656 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline BifTopic starter

  • Full Member
  • ***
  • Join Date: Aug 2009
  • Posts: 124
    • Show only replies by Bif
Why is SMT (multicore) support hard for Amiga OS?
« on: June 26, 2010, 01:06:18 AM »
I've been lurking around on here for a while now and I've now seen many posts where people reference the fact that adding support for more than one CPU to any flavour of Amiga OS seems difficult or impossible for some technical reason, especially lately with the X1000 CPU.

However, I've yet to find a detailed explanation/reference as to why it would be difficult. I'm sure such info has been posted somewhere, but I can't find it with a cursory search of Google and amiga.org. If you can point me to it that would be much appreciated.

I can't seem to shake my mid-life crisis which sees me spending way too much time over the last year reading about the Amiga. I was in love with it 20 years ago but then got busy with a software engineering career that took me away from it. I may now have ample free time to return to programming as a hobby and advancing Amiga OS (I guess it will have to be AROS) is something that seems to be drawing me in. While I have nothing against them, I can't stand the idea of Windows/Linux programming as a hobby as it has been beaten to death and there isn't much I feel i can contribute. I always wanted to program Amiga but never got far into it before getting sidetracked. So I don't know too much about Amiga OS.

Anyway my last 5 years I did almost nothing but multi-core software design and programming across a diverse array of hardware. I've never written a multi-core OS though. But from my user view, I don't get why multi-core is hard. Threads can run on whatever CPU, synchronization primitives built into the OS need to be updated to do the proper things across cores, and the kernel needs to know how to schedule cores? I must be missing something, obviously.

In my searching I did read AmigaOS 4.0 slides where it said multi-threading was added or being added - does that mean that an AmigaOS task can not have multiple threads? I guess I find that surprising if true, but not unbelievable, and I guess that would be a key problem since cores could only be allocated per task instead of per thread. And then I guess if AmigaOS/MorphOS/AROS only share common AmigaOS API up to 3.x it becomes a real challenge to create new OS APIs that they all standardize on?

Anyway sorry for all the clueless hypothesizing, but I really am curious where to get the lowdown. If I had more time I'd break out the AROS source and check but I won't have much time on my hands for a few months yet.

Thanks
 

Offline ajlwalker

  • Sr. Member
  • ****
  • Join Date: May 2004
  • Posts: 458
    • Show only replies by ajlwalker
Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #1 on: June 26, 2010, 10:53:30 AM »
I'd like to know too.
 

Offline kolla

Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #2 on: June 26, 2010, 11:01:37 AM »
SMT? Simultaneous multithreading?
B5D6A1D019D5D45BCC56F4782AC220D8B3E2A6CC
---
A3000/060CSPPC+CVPPC/128MB + 256MB BigRAM/Deneb USB
A4000/CS060/Mediator4000Di/Voodoo5/128MB
A1200/Blz1260/IndyAGA/192MB
A1200/Blz1260/64MB
A1200/Blz1230III/32MB
A1200/ACA1221
A600/V600v2/Subway USB
A600/Apollo630/32MB
A600/A6095
CD32/SX32/32MB/Plipbox
CD32/TF328
A500/V500v2
A500/MTec520
CDTV
MiSTer, MiST, FleaFPGAs and original Minimig
Peg1, SAM440 and Mac minis with MorphOS
 

Offline ElPolloDiabl

  • Hero Member
  • *****
  • Join Date: May 2009
  • Posts: 1702
    • Show only replies by ElPolloDiabl
Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #3 on: June 26, 2010, 11:35:50 AM »
I think you mean SMP though. Synchronous multiprocessing. The big IBM PowerPC chips have multithreading?
Go Go Gadget Signature!
 

Offline kolla

Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #4 on: June 26, 2010, 11:58:40 AM »
Quote from: ElPolloDiabl;567355
Synchronous multiprocessing

You mean symmetric multiprocessing?

I think it's now appearant why AmigaOS doesn't have either. :lol:
B5D6A1D019D5D45BCC56F4782AC220D8B3E2A6CC
---
A3000/060CSPPC+CVPPC/128MB + 256MB BigRAM/Deneb USB
A4000/CS060/Mediator4000Di/Voodoo5/128MB
A1200/Blz1260/IndyAGA/192MB
A1200/Blz1260/64MB
A1200/Blz1230III/32MB
A1200/ACA1221
A600/V600v2/Subway USB
A600/Apollo630/32MB
A600/A6095
CD32/SX32/32MB/Plipbox
CD32/TF328
A500/V500v2
A500/MTec520
CDTV
MiSTer, MiST, FleaFPGAs and original Minimig
Peg1, SAM440 and Mac minis with MorphOS
 

Offline Fats

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 672
    • Show only replies by Fats
Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #5 on: June 26, 2010, 12:57:48 PM »
Quote from: Bif;567304

Anyway my last 5 years I did almost nothing but multi-core software design and programming across a diverse array of hardware. I've never written a multi-core OS though. But from my user view, I don't get why multi-core is hard. Threads can run on whatever CPU, synchronization primitives built into the OS need to be updated to do the proper things across cores, and the kernel needs to know how to schedule cores? I must be missing something, obviously.
Thanks


AmigaOS uses a lot of public memory like Execbase. To allow multitasking access to these memory spaces, they are often surrounded by Forbid()/Permit() pairs. This is in system code, libraries and user programs.
Problem is that in a multi-core/multi-CPU occasion also the programs running on the other processor(s) have to be paused when a Forbid() call is made. This will make it very difficult to get any advantage of multiple cores or even may make it run slower due to the overhead.

greets,
Staf.
Trust me...                                              I know what I\'m doing
 

Offline ElPolloDiabl

  • Hero Member
  • *****
  • Join Date: May 2009
  • Posts: 1702
    • Show only replies by ElPolloDiabl
Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #6 on: June 26, 2010, 02:07:45 PM »
Quote from: kolla;567356
You mean symmetric multiprocessing?

I think it's now appearant why AmigaOS doesn't have either. :lol:

You don't hear the term much anymore, they are just called cores plus threads.
Go Go Gadget Signature!
 

Offline amigadave

  • Lifetime Member
  • Hero Member
  • *****
  • Join Date: Jul 2004
  • Posts: 3836
    • Show only replies by amigadave
    • http://www.EfficientByDesign.org
Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #7 on: June 26, 2010, 06:13:20 PM »
@Bif,

First off if it already has not been done, allow me to welcome you to the Amiga.org forums.  It is always good to see Amiga users with programming experience/talent return to the Amiga community, as we are woefully short on competent programmers (at least compared to the number of Amiga programmers there once were).

I can't answer the technical side of your questions, but you should be able to find previous forum threads that discuss multiple cores/multiple threading support, if not here at a.org I know I saw such a thread over at MorphZone.org not too long ago, but I do not remember the details of the discussion.  It would be great to see someone with lots of experience in multiple core/multiple threading software design take a look at the difficulties in implementing such support within AmigaOS4.x/MorphOS2.x/AROS.  Perhaps such an experienced person could come up with some new ideas to overcome the obstacles and figure out a way to take advantage of a second core in some way that would speed up the above mentioned OS'es and/or any newly written programs that run on those OS'es that could use the new ideas.  The proposed multiple core support planned for AmigaOS4.x is just on the wish list, or their "Road Map" and there is no target date for when (or if) it will be completed, or even if work on implementing it has been started.

Lastly, even if it proves to be impossible, or impractical to implement support for multiple core CPU's within AmigaOS4.x/MorphOS2.x/AROS, I hope that you will find the time to do some other Amiga programming in the future and that what ever code you do write will be able to be compiled for all three OS'es mentioned above.  One easy way to accomplish this is to use Hollywood4.5, or just about any C/C++ compiler to write your programs.  Hollywood comes with built-in support to compile for multiple OS'es, including MacOSX and Windows in addition to AmigaOS3.x, AmigaOS4.x and MorphOS2.x (I would have to look at the documentation again to see if it supports AROS and/or Linux).  Although Hollywood and Hollywood Designer are not "Low Level" programming languages, I have read that some very good programs have been written using them and that is where I am trying to concentrate my learning to program time.  From there I will probably try to learn C/C++ next.
How are you helping the Amiga community? :)
 

Offline BifTopic starter

  • Full Member
  • ***
  • Join Date: Aug 2009
  • Posts: 124
    • Show only replies by Bif
Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #8 on: June 26, 2010, 06:20:50 PM »
Quote from: Fats;567366
AmigaOS uses a lot of public memory like Execbase. To allow multitasking access to these memory spaces, they are often surrounded by Forbid()/Permit() pairs. This is in system code, libraries and user programs.
Problem is that in a multi-core/multi-CPU occasion also the programs running on the other processor(s) have to be paused when a Forbid() call is made. This will make it very difficult to get any advantage of multiple cores or even may make it run slower due to the overhead.

greets,
Staf.


Oops, yes, I did mean to say SMP, duh. SMT presents the same problem though.

Thanks for the insight Fats, that sheds a bit of light on it.

So it seems Forbid()/Permit() is a coarse-grained synchronization mechanism to allow shared access to resources. I'm thinking that shouldn't be a huge obstacle preventing multicore. Indeed while one core has a Forbid() taken out, another thread on another core might have to block/idle, which is not desirable.

However, I think every multicore OS already has this problem and suffers from it. There is not much way around it, access to shared resources requires synchronization. The Win32 API for example may not have equivalent Forbid/Permit, but when you call into the API to allocate memory or access the file system, it is performing it's own synchronization anyway. If two threads are accessing the file system, one will have to wait for the other to exit the critical parts of the API. Probably a key difference here is the granularity, in Win32 the file system may have one or more of its own mutexes, and the memory allocator a different one. So the file system access won't block the memory allocation system, and so on. In other ways the Forbid()/Permit() scheme probably has advantages, because each AmigaOS API call doesn't have to include the synchronization and thus will operate more efficiently. I've designed a number of APIs that work just this way, and execute on multicore just fine. Taking out a lock on each API call can get expensive as locks can get expensive.

The main reason I don't see the AmigaOS calls blocking being a huge issue is because a well written program that is using heaps of CPU probably shouldn't be spending all of it inside AmigaOS calls. You shouldn't have to call into AmigaOS to perform DSP, physics, rendering, or whatever other kind of expensive logic you need to execute that requires all that CPU. Memory allocation may be an issue but it shouldn't be too bad I think, and if you have to, you can create your own private heap to allocate from without the need for synchronization - where I come from you try to simply never reallocate memory so you don't even have to deal with the memory system. I'd think most AmigaOS calls would come down to user interface and IO. I can't see 10 programs all trying to access UI at once and having it stall things out. I think probably only file IO should be a real problem. And every other multicore OS is going to have the same blocking problem here. It's really not much of a problem in practice.

I think for multicore all you can do is try to minimize the time the OS holds locks on shared resources. If programs are written poorly such that they put Forbid() calls around large chunks of code it will prevent good multicore execution. But it would also be forbidding good single core execution as well as other tasks won't be able to get their timeslice if they are blocked out.

Ideally you can create lockless APIs...but realistically that's near impossible, especially for OS functionality I would think.
 
Anyway I'm just kind of babbling ... still wondering if there is something else big preventing AmigaOS going multi-core.
 

Offline koaftder

  • Hero Member
  • *****
  • Join Date: Apr 2004
  • Posts: 2116
    • Show only replies by koaftder
    • http://koft.net
Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #9 on: June 26, 2010, 06:33:34 PM »
Aren't the amiga line of OS's basically flat mode os's? Everything about the original AmigaOS design was a series of compromises to get the most performance. Flatmode is a fast as hell free for all with no security.
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #10 on: June 26, 2010, 06:44:14 PM »
@Bif

As Fats (or Staf as we know him on the AROS list), has pointed out, AmigaOS shares resources... Ok, the Forbid() problem is a big one, but now think about HOW the amiga shares resources. It's all pointer passing, you basically have no idea which task/process is using what memory... if you need atomic access to a resouce you NEED to stop all tasks/processes that are currently running on the system...

This is just another case of one simple design decision, to share memory pointers for a bit of extra speed, coming back to bite us 25 years later :(

Offline yakumo9275

  • Sr. Member
  • ****
  • Join Date: Jun 2008
  • Posts: 301
    • Show only replies by yakumo9275
    • http://mega-tokyo.com/blog
Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #11 on: June 26, 2010, 09:01:17 PM »
bif, you umay do better searching, this is a much hashed topic.
--/\\-[ Stu ]-/\\--
Commodore 128DCR, JiffyDOS, Ultimate 1541 II, uIEC/SD, CBM 1902A  Monitor
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #12 on: June 26, 2010, 09:17:05 PM »
Quote from: bloodline;567411
@Bif

As Fats (or Staf as we know him on the AROS list), has pointed out, AmigaOS shares resources... Ok, the Forbid() problem is a big one, but now think about HOW the amiga shares resources. It's all pointer passing, you basically have no idea which task/process is using what memory... if you need atomic access to a resouce you NEED to stop all tasks/processes that are currently running on the system...

This is just another case of one simple design decision, to share memory pointers for a bit of extra speed, coming back to bite us 25 years later :(

Strictly speaking, Forbid()/Permit() are not needed for the majority of AmigaOS thread exclusive access to (non-hardware) resources. For the most part, SignalSemaphores do a decent job of mediating access to items and lists in the system.
int p; // A
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #13 on: June 26, 2010, 10:02:40 PM »
Quote from: Karlos;567426
Strictly speaking, Forbid()/Permit() are not needed for the majority of AmigaOS thread exclusive access to (non-hardware) resources. For the most part, SignalSemaphores do a decent job of mediating access to items and lists in the system.
True, but Forbid() was quicker and easier... Let I also not forget that pointer passing also removed Data locality... Two threads on different CPU's could be sharing the same data... and that data could quite easily be located in two different caches unless marked non-cacheable... but no provision was ever made for that!

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Why is SMT (multicore) support hard for Amiga OS?
« Reply #14 on: June 26, 2010, 10:06:29 PM »
Quote from: bloodline;567434
True, but Forbid() was quicker and easier... Let I also not forget that pointer passing also removed Data locality... Two threads on different CPU's could be sharing the same data... and that data could quite easily be located in two different caches unless marked non-cacheable... but no provision was ever made for that!

This assumes that two CPUs are running entirely independently and that no mechanism for enforcing cache coherency exists. This is a very old problem that has been mitigated by hardware advancements quite some time ago. Are you familiar with the MOESI cache coherency model?

Most multicore processors use this or a similar strategy, where the assumption is that pushing data between cores to keep their caches coherent is not a bottleneck, but that talking to memory is.
« Last Edit: June 26, 2010, 10:11:41 PM by Karlos »
int p; // A