Page 2 of 3

Re: BareMetal OS v0.4.7

Posted: Wed May 12, 2010 1:04 pm
by IanSeyler
The images should be the correct ones. Try refreshing the page. BareMetal OS - Architecture. It should have a date of May 5th.

v0.4.8 should be coming out in the next few weeks. Changes have been made to the multi-processor functions and the C library for the OS now supports the SMP calls as well.

Code: Select all

// BareMetal compile
// gcc -c -m64 -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -o csmp.o csmp.c
// gcc -c -m64 -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -o libBareMetal.o libBareMetal.c
// ld -T app.ld -o csmp.app csmp.o libBareMetal.o


#include "libBareMetal.h"

void loop_a();
void loop_b();


int main()
{
	unsigned long var1=0, var2=0, local=0;

	b_smp_enqueue(&loop_a);			// Queue up some jobs
	b_smp_enqueue(&loop_b);			// The BareMetal OS queue is FIFO
	b_smp_enqueue(&loop_a);
	b_smp_enqueue(&loop_b);
	b_smp_enqueue(&loop_a);
	b_smp_enqueue(&loop_b);
	b_smp_enqueue(&loop_a);
	b_smp_enqueue(&loop_b);

	while (b_smp_queuelen() != 0)		// Check the length of the queue. If greater than 0 then try to run a queued job.
	{
		local = b_smp_dequeue();	// Grab a job from the queue. b_smp_dequeue returns the memory address of the code
		if (local != 0)			// If it was set to 0 then the queue was empty
			b_smp_run(local);	// Run the code
	}
	
	b_smp_wait();				// Wait for all CPU cores to finish
	b_print_string("end\n");

	return 0;
}


void loop_a()
{
	register unsigned long j,k;
	for(k=0; k<=665555; k++)
	{
		for(j=0; j<=100; j++){}
	}
	b_print_string("A is done\n");
}

void loop_b()
{
	register unsigned long j,k;
	for(k=0; k<=665555; k++)
	{
		for(j=0; j<=200; j++){}
	}
	b_print_string("B is done\n");
}

// EOF
The 4 instances of "loop_a" and "loop_b" will run in parallel (depending on the amount of CPU cores in the computer).

-Ian

Re: BareMetal OS v0.4.7

Posted: Wed May 12, 2010 2:15 pm
by Neolander
ReturnInfinity wrote:The images should be the correct ones. Try refreshing the page. BareMetal OS - Architecture. It should have a date of May 5th.
Yup. That post was made on May 4th, and the image changed so I updated it with a quick edit somewhere ^^
v0.4.8 should be coming out in the next few weeks. Changes have been made to the multi-processor functions and the C library for the OS now supports the SMP calls as well.
(...)
The 4 instances of "loop_a" and "loop_b" will run in parallel (depending on the amount of CPU cores in the computer).

-Ian
Great =D> Even though you might get some Elanore semaphore semaphore comments after displaying output from that ^^

Re: BareMetal OS v0.4.7

Posted: Thu May 13, 2010 2:15 pm
by IanSeyler
Sorry about that. I didn't notice that you edited your original post.

The "A", "B" stuff was just a proof of concept. The big thing now is to modify my Prime Numbers test program (a brute force test to check if a number is prime) to take advantage of multiple cores. I want to see the 2X speed increase using 2 CPU Cores instead of 1.

Here is the code so far: (Note: I haven't even attempted to compile it yet as it is unfinished)

Code: Select all

// BareMetal compile
// gcc -c -m64 -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -o primesmp.o primesmp.c -DBAREMETAL
// gcc -c -m64 -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -o libBareMetal.o libBareMetal.c
// ld -T app.ld -o primesmp.app primesmp.o libBareMetal.o

// maxn = 300000  primes = 25997
// maxn = 400000  primes = 33860
// maxn = 1000000 primes = 78498


#include "libBareMetal.h"

void prime_process();


int main()
{
	register unsigned long maxn=400000, primes=0, local=0, processes=1;
	unsigned char tstring[25];
	unsigned long start, finish, k;

	start = b_get_timercounter();		// Grab the starting time

	for (k=0; k<=processes; k++)
	{
		b_smp_enqueue(&prime_process);
	}

	while (b_smp_queuelen() != 0)		// Check the length of the queue. If greater than 0 then try to run a queued job.
	{
		local = b_smp_dequeue();	// Grab a job from the queue. b_smp_dequeue returns the memory address of the code
		if (local != 0)			// If it was set to 0 then the queue was empty
			b_smp_run(local);	// Run the code
	}
	
	b_smp_wait();				// Wait for all CPU cores to finish

	finish = b_get_timercounter();		// Grab the finish time
	b_int_to_string(primes, tstring);	// Print the amount of primes for verification
	b_print_string(tstring);
	b_print_string(" in ");
	finish = (finish - start) / 8;
	b_int_to_string(finish, tstring);
	b_print_string(tstring);
	b_print_string(" seconds\n");

	return 0;
}


// 1 process   - 1: 1 2 3 ...
// 2 processes - 1: 1 3 5 ...	2: 2 4 6 ...
// 3 processes - 1: 1 4 7 ...	2: 2 5 8 ...	3: 3 6 9 ...
// 4 processes - 1: 1 5 9 ...	2: 2 6 10 ...	3: 3 7 11 ...	4: 4 8 12 ...
// And so on.

void prime_process()
{
	register unsigned long i, j, tprimes=0;

	i = 0;	// Calculate where this process starts

	for(; i<=maxn; i+=processes)
	{
		for(j=2; j<=i-1; j++)
		{
			if(i%j==0) break; //Number is divisble by some other number. So break out
		}
		if(i==j)
		{
			tprimes = tprimes + 1;
		}
	} //Continue loop up to max number
	
	// add tprimes to primes
	primes = primes + tprimes;
}

// EOF
This is a modification of the prime.c program I have been using to benchmark performance between Linux and BareMetal OS running on the same physical hardware.

-Ian

Re: BareMetal OS v0.4.7

Posted: Wed May 19, 2010 8:58 am
by IanSeyler
Good news! Calculations in C with multiple CPU cores works correctly!

The code in the last post did work with a few alterations but there was a logic error. The prime_process() function would check even numbers as well. This would mean there was no performance increase using two processes on a dual-core system (One core would check the odd numbers and would take a long time and one core would check the even numbers and complete quickly). Dividing the workload in 4 worked correctly on a the dual-core system.

The new program only checks odd numbers and works correctly with two processes.

Code: Select all

// BareMetal compile
// gcc -c -m64 -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -o primesmp.o primesmp.c
// gcc -c -m64 -nostdlib -nostartfiles -nodefaultlibs -fomit-frame-pointer -o libBareMetal.o libBareMetal.c
// ld -T app.ld -o primesmp.app primesmp.o libBareMetal.o

// maxn = 10000   primes = 1229
// maxn = 100000  primes = 9592
// maxn = 300000  primes = 25997
// maxn = 400000  primes = 33860
// maxn = 1000000 primes = 78498


#include "libBareMetal.h"

void prime_process();

// primes is set to 1 since we don't calculate for '2' as it is a known prime number
unsigned long maxn=400000, primes=1, local=0, lock=0, process_stage=0, processes=8;
unsigned char tstring[25];

int main()
{
	unsigned long start, finish, k;
	
	process_stage = processes;

	start = b_get_timercounter();		// Grab the starting time

// Spawn the worker processes
	for (k=0; k<processes; k++)
	{
		b_smp_enqueue(&prime_process);
	}

// Attempt to run a process on this CPU Core
	while (b_smp_queuelen() != 0)		// Check the length of the queue. If greater than 0 then try to run a queued job.
	{
		local = b_smp_dequeue();	// Grab a job from the queue. b_smp_dequeue returns the memory address of the code
		if (local != 0)			// If it was set to 0 then the queue was empty
			b_smp_run(local);	// Run the code
	}

// No more jobs in the queue
	b_smp_wait();				// Wait for all CPU cores to finish

	finish = b_get_timercounter();		// Grab the finish time

// Print the results
	b_int_to_string(primes, tstring);	// Print the amount of primes for verification
	b_print_string(tstring);
	b_print_string(" in ");
	finish = (finish - start) / 8;
	b_int_to_string(finish, tstring);
	b_print_string(tstring);
	b_print_string(" seconds\n");

	return 0;
}


// prime_process() only works on odd numbers.
// The only even prime number is 2. All other even numbers can be divided by 2.
// 1 process	1: 3 5 7 ...
// 2 processes	1: 3 7 11 ...	2: 5 9 13 ...
// 3 processes	1: 3 9 15 ...	2: 5 11 17 ...	3: 7 13 19 ...
// 4 processes	1: 3 11 19 ...	2: 5 13 21 ...	3: 7 15 23 ...	4: 9 17 25...
// And so on.

void prime_process()
{
	register unsigned long h, i, j, tprimes=0;

	// Lock process_stage, copy it to local var, subtract 1 from process_stage, unlock it.
	os_smp_lock(lock);
	i = process_stage;
	if (i == 1)
	{
		i = 3;		// process 1 starts at 3
	}
	else
	{
		i = (i * 2) + 1;	// process 2 starts at 5 (2 * 2 + 1), process 3 starts at 7 (3 * 2 + 1)
	}
	process_stage--;
	os_smp_unlock(lock);

	h = processes * 2;

	// Process
	for(; i<=maxn; i+=h)
	{
		for(j=2; j<=i-1; j++)
		{
			if(i%j==0) break; // Number is divisble by some other number. So break out
		}
		if(i==j)
		{
			tprimes = tprimes + 1;
		}
	} // Continue loop up to max number

	// Add tprimes to primes.
	os_smp_lock(lock);
	primes = primes + tprimes;
	os_smp_unlock(lock);
}

// EOF
Application run-time test on a dual-core system:
1 process: 118 seconds
2 processes: 59 seconds
4 processes: 59 seconds
8 processes: 60 seconds
16 processes: 60 seconds

Version 0.4.8 will come out in the next few weeks. Currently working on command line argument passing to a C programs.

Also, I need a computer with more cores :P

Re: BareMetal OS v0.4.7

Posted: Thu May 20, 2010 9:00 pm
by inx
ReturnInfinity wrote:Also, I need a computer with more cores
Why not just emulate it? Sure, there's not going to be a performance increase, but it works as a proof of concept.

Re: BareMetal OS v0.4.7

Posted: Fri May 21, 2010 12:44 pm
by IanSeyler
As a proof of concept it does work. I have successfully emulated 64 CPUs under QEMU. QEMU (0.12.3) seems to only be able to emulate up to 91 CPU's but BareMetal OS should support 256.

BareMetal OS v0.4.8

Posted: Tue Jul 13, 2010 2:04 pm
by IanSeyler
Version 0.4.8 has been released. Documentation updates, bug fixes, additions to the C library, etc.

Included in the distribution is a program called 'primesmp'. This C program uses all of the available processors in the system to detect prime numbers (via brute force). The application performance scales with the amount of CPU cores in the system.

On a quad-core i3 @ 2.66GHz running PrimeSMP to calculate all primes between 1 and 400000:
1 Core - 46 seconds
2 Cores - 23 seconds
4 Cores - 12 seconds

Also by using the latest version of Pure64 we now support HyperThreading. From our testing it increases system performance by about 20%.Tests were done with an Intel D945GCLF2 board - Atom 330 CPU (Dual Core 1.6GHz), 2GiB RAM

Hyper-threading off : 269 seconds
Hyper-threading on : 223 seconds

http://www.returninfinity.com/baremetal.html

Re: BareMetal OS v0.4.9

Posted: Wed Sep 15, 2010 7:36 pm
by IanSeyler
BareMetal OS v0.4.9 has been released today. The OS now supports Ethernet access via the Realtek 8139 chipset. Functions for memory management (alloc/free) have also been added.

Work is also being done on a full C library here: http://code.google.com/p/barelibc/

Re: BareMetal OS v0.5.0

Posted: Tue Feb 15, 2011 12:25 pm
by IanSeyler
BareMetal OS v0.5.0 was released today. This is mainly a maintenance release.

The C library has been updated to support the latest versions of CGG and binutils.

Video performance has been improved.

Looking forward to v0.6.0: DMA access for Hard Drives, an improved C library, and some basic TCP/IP support.

Re: BareMetal OS v0.5.1

Posted: Mon May 16, 2011 11:41 am
by IanSeyler
BareMetal OS v0.5.1 was released today. This is a maintenance and feature release.

The major change is the network hardware support. BareMetal OS now supports the Intel Pro/1000 family of Ethernet chipsets (anything i8254x-based) as well as the Realtek 8169-based family (8169, 8110, 8168, and 8111). BareMetal can be run under VirtualBox with full network support (Great for testing).

Re: BareMetal OS v0.5.2

Posted: Wed Jul 06, 2011 11:45 am
by IanSeyler
BareMetal OS v0.5.2 was released today.

The Newlib C library has been ported to BareMetal OS so it is now possible to compile apps that use the standard ANSI C calls like printf(). This makes it a bit easier to compile existing code for the new system. File calls within Newlib have not been coded for yet so it is limited to STDIN, STDOUT, and STDERR.

ARP support has also been added for the IPv4 stack that is currently in progress.

A 64-bit BASIC interpreter as well as a Brainf*ck interpreter were also added as demo applications.

-Ian

Re: BareMetal OS v0.5.2

Posted: Fri Jul 08, 2011 8:40 am
by silversmith
Before you continue any further on BareMetal OS, go write an application for Android. Something with a couple of 'Activity's is sufficient. Where you are headed really fast is just going to land you where every OS for Intel chips has landed. We need a completely different paradigm of thought for multi-core and, you started on the right track, but dropping in a Standard C library indicates you may be losing your way - plus the Standard library isn't exactly tiny. An Android 'Activity' is a self-contained unit of logic. As a generalized simplification, only one Activity is running at one time. Think of that as similar to the "one task per core" objective you have in mind. IMO, you need to do something similar for C before continuing with Bare Metal OS. From a C perspective, the Android way of doing things would essentially be multiple 'main()'s inside a single "program" - that is, multiple entry points. Multi-core programming requires a completely different way of thinking from traditional techniques. C is a one-task pony that was designed ages ago and still doesn't understand what multithreading and multi-core are. Shoehorning the current design paradigm of "each program has a single entry-point" into a multi-core environment is going to create a mess. To fully leverage multi-core, C itself needs to be changed.

Just a thought - something to chew on. Obviously, anyone looking at BareMetal in the first place is going to have serious processing needs. But let's say, for instance, this gets to be like Linux where it takes off and spawns a complete end-user OS with a large fan base. That's how far ahead I'm thinking here. You haven't fundamentally changed anything and therefore this will likely just be something obscure only used by a limited number of people...projects like that tend to die slowly. They're fun and neat, but that's it. This project has potential to be a serious contender to everything out there.

Re: BareMetal OS v0.5.2

Posted: Fri Jul 08, 2011 10:16 am
by bluemoon
silversmith wrote:Before you continue any further on BareMetal OS, go write an application for Android.
I guess his project is an OS but not application, so where did the Android came in?
Multi-core programming requires a completely different way of thinking from traditional techniques. C is a one-task pony that was designed ages ago and still doesn't understand what multithreading and multi-core are.
Check pthread(and its variants) for traditional parallel computing, and perhaps OpenMP. Yes they works in C as well.
the current design paradigm of "each program has a single entry-point" into a multi-core environment is going to create a mess. To fully leverage multi-core, C itself needs to be changed.
It really does not matter if your program starts as single entry point and then create threads.
If you really want to starts with multiple entry point you can create them in startup code, for example hide them within process creation stub, or CRT0.o

The real issue is that application does not know about system loading and cannot do load balancing without the help of information from kernel scheduler, however, this issue is irrelevant to programming language.
You haven't fundamentally changed anything and therefore this will likely just be something obscure only used by a limited number of people...projects like that tend to die slowly. They're fun and neat, but that's it. This project has potential to be a serious contender to everything out there.
IMO if you plan to make a successful OS, people suggests you need good marketing instead of anything significant in technology. Well, I have not managed to make a successful OS so I'm really not sure on it. For me, fun and neat would be the ultimate goal for now.

Re: BareMetal OS v0.5.2

Posted: Fri Jul 08, 2011 3:52 pm
by cxzuk
I think BareMetal does exactly what its set out to do.

Don't get me wrong, I agree with all your points. We do need a change of paradigm, a change of language, workflow, understanding etc.. but that really is something that needs heavy research into.

Microkernels are now in the 3rd? generation.. and they have hit road blocks in understanding in some way. I dont fully understand the problems, but I personally see that to create an operating system that is "better" than our current ways just isnt going to happen any time soon and most likely by anyone of us.

Mike

Re: BareMetal OS v0.5.3

Posted: Thu Feb 23, 2012 1:59 pm
by IanSeyler
BareMetal OS v0.5.3 was released today.

Uses the latest Pure64 for IO-APIC support.
Newlib v1.20 supported.
Added an 'ipconfig' utility for setting up an IP address.
Basic ARP and ICMP support so it responds to ping.

Next release will hopefully have a full IP stack.

-Ian