Page 1 of 1

Mapping memory via Grub taking too long

Posted: Fri Sep 13, 2013 12:20 pm
by barkingtreefrog
I've got to the point where I'm detecting memory, I've decided to use multiboot.h and get my memory map from Grub following the tutorial I'm using this code

Code: Select all

typedef struct multiboot_memory_map {
	unsigned int size;
	unsigned int base_addr_low,base_addr_high;
// You can also use: unsigned long long int base_addr; if supported.
	unsigned int length_low,length_high;
// You can also use: unsigned long long int length; if supported.
	unsigned int type;
} multiboot_memory_map_t;
 
int main(multiboot_info* mbt, unsigned int magic) {
	...
	multiboot_memory_map_t* mmap = mbt->mmap_addr;
	while(mmap < mbt->mmap_addr + mbt->mmap_length) {
		...
		mmap = (multiboot_memory_map_t*) ( (unsigned int)mmap + mmap->size + sizeof(unsigned int) );
	}
	...
}
It works fine but takes over 5 minutes. I'm running my iso in VirtualBox. Now here's the odd part. I wrote to the screen the the loop at one point because I thought my OS had froze. If I write to the screen in that loop then the entire process takes less than 2 seconds. If I don't have anything in my loop by what is above it takes way, way to long. Is there something simple I might be overlooking here?

Also, I only have 128MB allocated for my virtual machine.

Re: Mapping memory via Grub taking too long

Posted: Fri Sep 13, 2013 1:30 pm
by Kortath
barkingtreefrog wrote:I've got to the point where I'm detecting memory, I've decided to use multiboot.h and get my memory map from Grub following the tutorial I'm using this code

Code: Select all

typedef struct multiboot_memory_map {
	unsigned int size;
	unsigned int base_addr_low,base_addr_high;
// You can also use: unsigned long long int base_addr; if supported.
	unsigned int length_low,length_high;
// You can also use: unsigned long long int length; if supported.
	unsigned int type;
} multiboot_memory_map_t;
 
int main(multiboot_info* mbt, unsigned int magic) {
	...
	multiboot_memory_map_t* mmap = mbt->mmap_addr;
	while(mmap < mbt->mmap_addr + mbt->mmap_length) {
		...
		mmap = (multiboot_memory_map_t*) ( (unsigned int)mmap + mmap->size + sizeof(unsigned int) );
	}
	...
}
It works fine but takes over 5 minutes. I'm running my iso in VirtualBox. Now here's the odd part. I wrote to the screen the the loop at one point because I thought my OS had froze. If I write to the screen in that loop then the entire process takes less than 2 seconds. If I don't have anything in my loop by what is above it takes way, way to long. Is there something simple I might be overlooking here?

Also, I only have 128MB allocated for my virtual machine.

This may seem a little off topic, and not sure if this helps or not, but I setup my VirtualBox with 256 MB ram and the video with 32 MB of RAM. They seemed to be the "sweet" spot for my projects.

Re: Mapping memory via Grub taking too long

Posted: Fri Sep 13, 2013 9:24 pm
by darkinsanity
Hm...
Did you make sure that it's the loop that is taking so long? Did you add output-statements directly before and after the loop?
Did you try it in another emulator?
Whats the complete code inside the loop?

Also I recommend that you use the structs defined in multiboot.h instead of creating your own.

Re: Mapping memory via Grub taking too long

Posted: Sat Sep 14, 2013 12:42 am
by Love4Boobies
The code you've showed us is not sufficient to reproduce the problem. Could you link us to your repository?

Until you do, you should still fix some unrelated problems with your code:
  • As C doesn't require that structures be packed, yours only works by sheer luck and can break as soon as you change the ABI. Either do proper serialization, using an array, or (sigh) use a compiler-specific extension, such as GCC's __attribute__((packed)).
  • Similarly, you should be using fixed-width integer types, as the ones you're using don't have fixed widths or sizes; they're ABI-dependent.
  • Finally, calling conventions also vary from ABI to ABI. It's safest to pass magic and mbt as external objects rather than as parameters.
  • Given that multiboot_memory_map_t is not an opaque type, why do you typedef it?
  • Why does your main function expect to have a return value?

Re: Mapping memory via Grub taking too long

Posted: Sat Sep 14, 2013 10:59 am
by Kortath
Maybe I am reading this wrong.. but.. what exactly is multiboot_memory_map_t returning ? Because when you call this, your not assigning anything to multiboot_memory_map_t and so nothing is being returned.

Code: Select all

typedef struct multiboot_memory_map {
   unsigned int size;
   unsigned int base_addr_low,base_addr_high;
   unsigned int length_low,length_high;
   unsigned int type;
} multiboot_memory_map_t;
Also....
unless I just don't know C well enough, which is also possible.. ( winks ), in all the books on C that I have read, you return from a function like this ( pseudo code )..

NOTE : I am assuming your coding this in C.

Code: Select all

your_function {
     return  what_you_want_to_return;
}
EXAMPLE :
http://www.mycplus.com/tutorials/c-prog ... functions/

Re: Mapping memory via Grub taking too long

Posted: Sat Sep 14, 2013 7:31 pm
by Love4Boobies
Is Kortath a troll or just incompetent?

Re: Mapping memory via Grub taking too long

Posted: Sat Sep 14, 2013 9:40 pm
by Kortath
Love4Boobies wrote:Is Kortath a troll or just incompetent?
How does this question help ? All your questioning does is provoke a negative reaction and has no baring on the OP's question.

Now to stay on topic, if i am wrong in my earlier reply to the OP, then please explain why.

Re: Mapping memory via Grub taking too long

Posted: Sat Sep 14, 2013 9:57 pm
by zhiayang
Kortath wrote:Maybe I am reading this wrong.. but.. what exactly is multiboot_memory_map_t returning ? Because when you call this, you're not assigning anything to multiboot_memory_map_t and so nothing is being returned.

Code: Select all

typedef struct multiboot_memory_map {
   unsigned int size;
   unsigned int base_addr_low,base_addr_high;
   unsigned int length_low,length_high;
   unsigned int type;
} multiboot_memory_map_t;
Also....
unless I just don't know C well enough, which is also possible.. ( winks ), in all the books on C that I have read, you return from a function like this ( pseudo code )..

NOTE : I am assuming you're coding this in C.

Code: Select all

your_function {
     return  what_you_want_to_return;
}
EXAMPLE :
http://www.mycplus.com/tutorials/c-prog ... functions/



Look again.
typedef.
struct.
_t.

That is clearly *NOT* a function.
Either stop trolling, or go read up on C again.
There is no direct assignment, nothing to indicate a function call (); or anything of the sort.

Also:
I don't know where you're from, but every god-damned school should allocate at least one hour per week to teach children the difference between

YOUR
and
YOU'RE

in english lesson.

Re: Mapping memory via Grub taking too long

Posted: Sat Sep 14, 2013 10:17 pm
by Kortath
requimrar wrote:
Kortath wrote:Maybe I am reading this wrong.. but.. what exactly is multiboot_memory_map_t returning ? Because when you call this, you're not assigning anything to multiboot_memory_map_t and so nothing is being returned.

Code: Select all

typedef struct multiboot_memory_map {
   unsigned int size;
   unsigned int base_addr_low,base_addr_high;
   unsigned int length_low,length_high;
   unsigned int type;
} multiboot_memory_map_t;
Also....
unless I just don't know C well enough, which is also possible.. ( winks ), in all the books on C that I have read, you return from a function like this ( pseudo code )..

NOTE : I am assuming you're coding this in C.

Code: Select all

your_function {
     return  what_you_want_to_return;
}
EXAMPLE :
http://www.mycplus.com/tutorials/c-prog ... functions/



Look again.
typedef.
struct.
_t.

That is clearly *NOT* a function.
Either stop trolling, or go read up on C again.
There is no direct assignment, nothing to indicate a function call (); or anything of the sort.

Also:
I don't know where you're from, but every god-damned school should allocate at least one hour per week to teach children the difference between

YOUR
and
YOU'RE

in english lesson.
Thanks for the info. I clearly misread it as a function.

Re: Mapping memory via Grub taking too long

Posted: Sun Sep 15, 2013 9:58 am
by dozniak
requimrar wrote:I don't know where you're from, but every god-damned school should allocate at least one hour per week to teach children the difference between

YOUR
and
YOU'RE

in english lesson.
Five thumbs up. Your right!

Re: Mapping memory via Grub taking too long

Posted: Sun Sep 15, 2013 11:06 am
by zhiayang
dozniak wrote:
requimrar wrote:I don't know where you're from, but every god-damned school should allocate at least one hour per week to teach children the difference between

YOUR
and
YOU'RE

in english lesson.
Five thumbs up. Your right!

Hmm? all I see is a wall, there's nothing on my right.

Re: Mapping memory via Grub taking too long

Posted: Mon Sep 16, 2013 2:44 am
by Love4Boobies
Hmm. There were supposed to be five thumbs there. Who did I send them to then?

Re: Mapping memory via Grub taking too long

Posted: Mon Sep 16, 2013 3:14 am
by zhiayang
Love4Boobies wrote:Hmm. There were supposed to be five thumbs there. Who did I send them to then?

Oh never mind, I found them in my fridge:


Re: Mapping memory via Grub taking too long

Posted: Mon Sep 16, 2013 7:54 am
by barkingtreefrog
darkinsanity wrote:Hm...
Did you make sure that it's the loop that is taking so long? Did you add output-statements directly before and after the loop?
Did you try it in another emulator?
Whats the complete code inside the loop?

Also I recommend that you use the structs defined in multiboot.h instead of creating your own.
I did add output statements before, after, and in the loop. If I place an output statement inside of the loop then the mapping is near instant. Thanks for all of the replies everyone and sorry for the late response. I'll get back to all of you with some more code and/or updates after work tonight. :)