Discussion:
Multithreading in gem5, full system mode
(too old to reply)
Jasmin Jahic
2017-01-17 10:28:53 UTC
Permalink
Hello,

I have one question regarding multi threading in gem5, in full system mode.
Since gem5 is seen as one process at host OS, how does gem5 actually
emulate multiple threads/processes? Let's say that we have 4 core CPU and
several processes and threads. Are these run in parallel really (one
instruction of this thread, then one instruction of another thread...?) or
there is some more complex mechanism?

Is there perhaps a presentation or document which explains this?

Best regards,
Jasmin JAHIC
Jason Lowe-Power
2017-01-17 14:59:48 UTC
Permalink
Hi Jasmin,

gem5 is an event-driven simulator. So, when there are multiple objects
(e.g., multiple CPU cores, or caches, or memory controllers, etc.) all of
these objects can execute in parallel in simulated time (or guest time to
use virtual machine nomenclature). The CPU models don't necessarily execute
one instruction at a time. Instead they are simulated at the clock-cycle
level. Each action which takes place at some clock-cycle boundary is
scheduled and then executed as an event in the event-driven simulation.

gem5 is mostly single threaded. All of the CPUs in your simulated system,
and all of the other objects like caches, etc. are simulated in a single
host thread. There are a few places where this isn't true, but it's unusual
to run gem5 with parallel event queues.

Hopefully this helps explain things. Let us know if you have more questions.

Cheers,
Jason
Post by Jasmin Jahic
Hello,
I have one question regarding multi threading in gem5, in full system
mode. Since gem5 is seen as one process at host OS, how does gem5 actually
emulate multiple threads/processes? Let's say that we have 4 core CPU and
several processes and threads. Are these run in parallel really (one
instruction of this thread, then one instruction of another thread...?) or
there is some more complex mechanism?
Is there perhaps a presentation or document which explains this?
Best regards,
Jasmin JAHIC
_______________________________________________
gem5-users mailing list
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
--
Jason
Jasmin Jahic
2017-01-17 21:32:17 UTC
Permalink
Dear Jason,

thank you for your answer. It gives me a hint how does gem5 work, but I am
unsure about the details. Is there any document which explains this?

To be concrete, if there are 4 cores and 4 threads, within once cycle, each
of them executes tick() on their own?

Best regards,
Jasmin
Post by Jason Lowe-Power
Hi Jasmin,
gem5 is an event-driven simulator. So, when there are multiple objects
(e.g., multiple CPU cores, or caches, or memory controllers, etc.) all of
these objects can execute in parallel in simulated time (or guest time to
use virtual machine nomenclature). The CPU models don't necessarily execute
one instruction at a time. Instead they are simulated at the clock-cycle
level. Each action which takes place at some clock-cycle boundary is
scheduled and then executed as an event in the event-driven simulation.
gem5 is mostly single threaded. All of the CPUs in your simulated system,
and all of the other objects like caches, etc. are simulated in a single
host thread. There are a few places where this isn't true, but it's unusual
to run gem5 with parallel event queues.
Hopefully this helps explain things. Let us know if you have more questions.
Cheers,
Jason
Post by Jasmin Jahic
Hello,
I have one question regarding multi threading in gem5, in full system
mode. Since gem5 is seen as one process at host OS, how does gem5 actually
emulate multiple threads/processes? Let's say that we have 4 core CPU and
several processes and threads. Are these run in parallel really (one
instruction of this thread, then one instruction of another thread...?) or
there is some more complex mechanism?
Is there perhaps a presentation or document which explains this?
Best regards,
Jasmin JAHIC
_______________________________________________
gem5-users mailing list
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
--
Jason
_______________________________________________
gem5-users mailing list
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
Matthias Jung
2017-01-17 23:24:38 UTC
Permalink
Hi Jason, Jasmin,

I think what he wants to ask is if gem5 is using like HDL simulators or SystemC
delta cycles - a two dimensional time in order to simulate concurrency?

Regards
Matthias
Post by Jasmin Jahic
Dear Jason,
thank you for your answer. It gives me a hint how does gem5 work, but I am unsure about the details. Is there any document which explains this?
To be concrete, if there are 4 cores and 4 threads, within once cycle, each of them executes tick() on their own?
Best regards,
Jasmin
Hi Jasmin,
gem5 is an event-driven simulator. So, when there are multiple objects (e.g., multiple CPU cores, or caches, or memory controllers, etc.) all of these objects can execute in parallel in simulated time (or guest time to use virtual machine nomenclature). The CPU models don't necessarily execute one instruction at a time. Instead they are simulated at the clock-cycle level. Each action which takes place at some clock-cycle boundary is scheduled and then executed as an event in the event-driven simulation.
gem5 is mostly single threaded. All of the CPUs in your simulated system, and all of the other objects like caches, etc. are simulated in a single host thread. There are a few places where this isn't true, but it's unusual to run gem5 with parallel event queues.
Hopefully this helps explain things. Let us know if you have more questions.
Cheers,
Jason
Hello,
I have one question regarding multi threading in gem5, in full system mode. Since gem5 is seen as one process at host OS, how does gem5 actually emulate multiple threads/processes? Let's say that we have 4 core CPU and several processes and threads. Are these run in parallel really (one instruction of this thread, then one instruction of another thread...?) or there is some more complex mechanism?
Is there perhaps a presentation or document which explains this?
Best regards,
Jasmin JAHIC
_______________________________________________
gem5-users mailing list
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
--
Jason
_______________________________________________
gem5-users mailing list
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
_______________________________________________
gem5-users mailing list
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
Jason Lowe-Power
2017-01-18 15:16:26 UTC
Permalink
Hi Jasmin,

To answer your question: Yes. Every SimObject in gem5 can schedule and
execute events for any tick.

Note: Ticks are usually running at 1 THz (1 tick = 1 picosecond), though
this is an option when initializing the system in the Python config files.
So, if you want to schedule an event for the next cycle and your cycle time
is 1 GHz, then you schedule the event for 1000 ticks in the future.

Every event calls a "process()" function. You can do anything you want
within this process function, including scheduling new events.

For more information:
1. A very high-level idea of how to create events can be found in my
Learning gem5 book: http://learning.gem5.org/book/part2/events.html
2. The code is the best place to understand how things work. See
src/sim/eventq* and src/sim/clocked_object.* for details of the event queue.

As for the "delta cycle" feature in SystemC, I'm not very familiar with it,
but I can try to explain how gem5 relates.
gem5 does not have the idea of two phase execution of events or an
evaluation and update phase. gem5 logically only has a single event queue.
You *can* schedule an event for the same tick, if needed, but this is quite
brittle in gem5. Additionally, gem5 supports event priorities, which can
solve some of the same issues as delta cycles (I think). Though, the event
priorities are rarely used in practice. Hopefully this helps some.

Cheers,
Jason
Post by Matthias Jung
Hi Jason, Jasmin,
I think what he wants to ask is if gem5 is using like HDL simulators or SystemC
delta cycles - a two dimensional time in order to simulate concurrency?
Regards
Matthias
Post by Jasmin Jahic
Dear Jason,
thank you for your answer. It gives me a hint how does gem5 work, but I
am unsure about the details. Is there any document which explains this?
Post by Jasmin Jahic
To be concrete, if there are 4 cores and 4 threads, within once cycle,
each of them executes tick() on their own?
Post by Jasmin Jahic
Best regards,
Jasmin
Hi Jasmin,
gem5 is an event-driven simulator. So, when there are multiple objects
(e.g., multiple CPU cores, or caches, or memory controllers, etc.) all of
these objects can execute in parallel in simulated time (or guest time to
use virtual machine nomenclature). The CPU models don't necessarily execute
one instruction at a time. Instead they are simulated at the clock-cycle
level. Each action which takes place at some clock-cycle boundary is
scheduled and then executed as an event in the event-driven simulation.
Post by Jasmin Jahic
gem5 is mostly single threaded. All of the CPUs in your simulated
system, and all of the other objects like caches, etc. are simulated in a
single host thread. There are a few places where this isn't true, but it's
unusual to run gem5 with parallel event queues.
Post by Jasmin Jahic
Hopefully this helps explain things. Let us know if you have more
questions.
Post by Jasmin Jahic
Cheers,
Jason
Hello,
I have one question regarding multi threading in gem5, in full system
mode. Since gem5 is seen as one process at host OS, how does gem5 actually
emulate multiple threads/processes? Let's say that we have 4 core CPU and
several processes and threads. Are these run in parallel really (one
instruction of this thread, then one instruction of another thread...?) or
there is some more complex mechanism?
Post by Jasmin Jahic
Is there perhaps a presentation or document which explains this?
Best regards,
Jasmin JAHIC
_______________________________________________
gem5-users mailing list
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
--
Jason
_______________________________________________
gem5-users mailing list
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
_______________________________________________
gem5-users mailing list
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
_______________________________________________
gem5-users mailing list
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
--
Jason
Matthias Jung
2017-01-18 20:18:46 UTC
Permalink
Hi Jasmin,

I refer to a thread on the mailing list from 2014: "Simulation core of gem5“
As part of the initialisation, the various SimObjects schedule their own
events and place them on the event queue (there can as many event queues
as you want, but in most cases there will only be a single one). This is
done as part of the init(), initState/loadState, startup() sequence that
takes place when launching the simulator.
The objects are traversed in the order they were created, so if Object A
and Object B both create events at time T, then Object A will have its
event executed first.
so its in fact a two dimensional time.
For example, consider the simulation objects Obj{1,2,3} are cores:

Tick Obj1 Obj2 Obj3
0 eventA
1 eventB eventC
2 eventD

so the single threaded simulator will execute it in the following order,
assuming that Obj2 earlier scheduled its eventB:

eventA
proceed with time
eventB
eventC
proceed with time
eventD
proceed with time
The event queue works like any 'normal' discrete-event simulator. It is
sorted on time, denoted in Ticks, and after the initalisation is done, the
queue picks the first event, updates the current tick to match the time of
this event, and then processes/executes the event. There is also a notion
of even priorities to order events within the same tick. This is used,
amongst other things, to ensure that all Œexecution¹ is done before
dumping statistics.
In the execution of an event more events may be created, also for the
current tick. If this is the case they are insertion sorted into the event
queue based on their tick and priority. They will thus happen after any
existing events in the current tick that have the same priority.
Have a look at eventq.hh/cc to see the details of how this works.
I hope that answered your question ;)

Regards
Matthias

Continue reading on narkive:
Loading...