[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
BOUNCE rtl@rtlinux.org: Approval required: Non-member submission from ["Kalyanaraman, Sivakumar (CTS)" <KSiva@chn.COGNIZANT.CRO (fwd)
- To: rtl@rtlinux.org
- Subject: BOUNCE rtl@rtlinux.org: Approval required: Non-member submission from ["Kalyanaraman, Sivakumar (CTS)" <KSiva@chn.COGNIZANT.CRO (fwd)
- From: root <root>
- Date: Mon, 7 May 2001 03:10:00 -0600 (MDT)
>From owner-rtl Thu May 3 08:12:51 2001
Received: from ctsincsisxic.Cognizant.com ([202.54.64.136])
by hq.fsmlabs.com (8.11.2/8.11.2) with SMTP id f43ECnJ16441
for <rtl@rtlinux.org>; Thu, 3 May 2001 08:12:49 -0600
Received: from 10.236.2.7 by ctsincsisxic.Cognizant.com (InterScan E-Mail VirusWall NT); Thu, 03 May 2001 19:42:12 +0530
Received: by CTSINCSISXIC with Internet Mail Service (5.5.2650.21)
id <KGV4MRS1>; Thu, 3 May 2001 19:42:12 +0530
Message-ID: <DDD04F4480FED411AB5D00508BFD7A440108FD@CTSINTDLSXUA>
From: "Kalyanaraman, Sivakumar (CTS)" <KSiva@chn.COGNIZANT.COM>
To: "'rtl'" <rtl@rtlinux.org>
Subject: varying execution times
Date: Thu, 3 May 2001 19:37:26 +0530
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2650.21)
Content-Type: multipart/mixed;
boundary="----_=_NextPart_000_01C0D3DA.620993E0"
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_000_01C0D3DA.620993E0
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C0D3DA.620993E0"
------_=_NextPart_001_01C0D3DA.620993E0
Content-Type: text/plain;
charset="iso-8859-1"
Hi,
I am trying to write a small module that can simulate dyn. memory
management.
On init. it gets a chunk of memory from the kernel . requests to my_malloc
are then done by the function in this module.
i see that the execution time of this function varies from 10-30 micro
seconds......even if only one RT thread runs......
this is something i cannot reason out why ...
the two files are attached.
<<rt_mem_mgr.h>> <<mod1.c>>
thanks for any help ....
siva
------_=_NextPart_001_01C0D3DA.620993E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2652.35">
<TITLE>varying execution times</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=3D2 FACE=3D"Arial">Hi,</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">I am trying to write a small module =
that can simulate dyn. memory management.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">On init. it gets a chunk of memory =
from the kernel . requests to my_malloc are then done by the function =
in this module.</FONT></P>
<P><FONT SIZE=3D2 FACE=3D"Arial">i see that the execution time of this =
function varies from 10-30 micro seconds......even if only one RT =
thread runs......</FONT></P>
<P><FONT SIZE=3D2 FACE=3D"Arial">this is something i cannot reason out =
why ...</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">the two files are attached.</FONT>
</P>
<BR>
<P><FONT FACE=3D"Arial" SIZE=3D2 COLOR=3D"#000000"> =
<<rt_mem_mgr.h>> </FONT><FONT FACE=3D"Arial" SIZE=3D2 =
COLOR=3D"#000000"> <<mod1.c>> </FONT>
</P>
<P><FONT COLOR=3D"#0000FF" FACE=3D"Comic Sans MS">thanks for any help =
....</FONT>
<BR><FONT COLOR=3D"#0000FF" FACE=3D"Comic Sans MS">siva</FONT>
</P>
<BR>
</BODY>
</HTML>
------_=_NextPart_001_01C0D3DA.620993E0--
------_=_NextPart_000_01C0D3DA.620993E0
Content-Type: application/octet-stream;
name="rt_mem_mgr.h"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="rt_mem_mgr.h"
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mm.h>
typedef long long ttt;
ttt t1,t2;
struct chunk_allocs;
typedef struct chunk {
struct chunk * next;
char * start_addr;
struct chunk_allocs * alloc;
int len_free;
int max_contig_free;
} mem_chunks;
#define MAX_SUB_ALLOC 100
#define CHUNK_SIZE 0x10000
struct chunk_allocs {
int offset[MAX_SUB_ALLOC];
int length[MAX_SUB_ALLOC];
int next[MAX_SUB_ALLOC];
int first_alloc;
int first_free;
};
mem_chunks * chk_list =3D NULL;
typedef struct chunk_allocs mem_allocs;
int init_mem_mgr(int num_chunks)
{
int i;
mem_chunks * chunk ;
for (i=3D0;i<num_chunks;i++)
{
chunk =3D (mem_chunks *) kmalloc(sizeof(mem_chunks),GFP_KERNEL);
init(chunk);
}
return 1;
}
void init(mem_chunks * chunk)
{
mem_allocs * chk_alloc;
int i;
chk_alloc =3D (mem_allocs *)kmalloc(sizeof(mem_allocs),GFP_KERNEL);
chunk->next =3D chk_list;
chk_list =3D chunk;=09
chunk->start_addr =3D (char *) kmalloc(CHUNK_SIZE,GFP_KERNEL);
chunk->len_free =3D 0x10000;
chunk->max_contig_free =3D CHUNK_SIZE;
chunk->alloc =3D chk_alloc;
=09
=09
for(i=3D0;i<MAX_SUB_ALLOC - 1;i++)
{
chk_alloc->next[i] =3D i + 1;
chk_alloc->length[i] =3D 0;
}
chk_alloc->next[i] =3D -1;
chk_alloc->length[i] =3D 0;;
chk_alloc->first_alloc =3D -1;
chk_alloc->first_free =3D 0;
chk_alloc->offset[0] =3D 0;
chk_alloc->length[0] =3D CHUNK_SIZE;
=09
return;
}
static inline char * del_from_free_list(int size)
{
int prev,curr,next;
int retoff;
int mlen;
int done =3D 0;
mem_chunks * cnklist;
mem_allocs * alloc;
t1 =3D gethrtime();
if(size<=3D0) return 0;
for(cnklist =3D chk_list;cnklist;cnklist =3D cnklist->next)
if (cnklist->max_contig_free >=3D size)
break;
if (!cnklist) return 0;
alloc =3D cnklist->alloc;
prev =3D curr =3D alloc->first_free;
while(curr !=3D -1)
if (alloc->length[curr] < size)
{
prev=3Dcurr;
curr =3D alloc->next[curr];
}
else=20
break;
if(curr =3D=3D -1) return 0;
next =3D alloc->next[curr];
if (prev =3D=3D curr)
alloc->first_free =3D next;
else
alloc->next[prev] =3D next;
mlen =3D 0;
=09
alloc->next[curr] =3D alloc->first_alloc;
alloc->first_alloc =3D curr;
=09
cnklist->max_contig_free -=3D size;
if (alloc->length[curr] < (size+20))
return (alloc->offset[curr] + cnklist->start_addr);
/*** CAN i Add after current ??? *****/
if (alloc->offset[curr] + alloc->length[curr] =3D=3D =
alloc->offset[next])
{
alloc->length[next]+=3D(alloc->length[curr] - size);
mlen =3D alloc->length[next];
retoff =3D alloc->offset[curr];
done =3D 1;
}
/**** optimize , may be bigger if added to prev .....greeedy ***/
if (prev !=3D curr && (alloc->offset[prev] + alloc->length[prev] =
=3D=3D alloc->offset[curr]))
{
if ((alloc->length[prev] + alloc->length[curr] - size) > mlen)
{
alloc->length[next]-=3D(alloc->length[curr] - size);
alloc->length[prev]+=3D(alloc->length[curr] - size);
mlen =3D alloc->length[prev];
retoff =3D alloc->offset[curr] + alloc->length[curr] - size;
done =3D 1;
}
}
if (!done)
{
int p;
/* creating a new small hole..add to mem list if there is space*/
for(p=3D0;p<MAX_SUB_ALLOC;p++)
if (alloc->length[p] =3D=3D 0)
{
alloc->length[p] =3D alloc->length[curr] - size;
alloc->offset[p] =3D alloc->offset[curr] + size;
if (p !=3D alloc->first_free)
{
alloc->next[p] =3D alloc->first_free;
alloc->first_free =3D p;
}
break;
}
}
alloc->length[curr] =3D size;
// retoff =3D alloc->offset[curr];
=09
if (cnklist->max_contig_free < mlen)
cnklist->max_contig_free =3D mlen;
t2 =3D gethrtime();
printk("\n Diff in malloc %d",t2-t1);
return alloc->offset[curr] + cnklist->start_addr;
}
static inline void add_to_free_list(char * addr)
{
int prev,curr,next,to_add;
int done;
char * retval;
mem_chunks * cnklist;
int curr_offset,addr_end;
mem_allocs * alloc;
int mlen =3D 0;
if(!addr) return;
t1 =3Dgethrtime();
for(cnklist =3D chk_list;cnklist;cnklist =3D cnklist->next)
if (cnklist->start_addr <=3D addr && addr < cnklist->start_addr + =
CHUNK_SIZE)
break;
if (!cnklist) return;
alloc =3D cnklist->alloc;
prev =3D curr =3D alloc->first_alloc;
curr_offset =3D addr - cnklist->start_addr;
while(curr !=3D -1)
{
if (alloc->offset[curr] =3D=3D curr_offset) break;
prev=3Dcurr;
curr =3D alloc->next[curr];
}
if (curr =3D=3D -1) return;
next =3D alloc->next[curr];
if (prev =3D=3D curr)
alloc->first_alloc =3D next;
else
alloc->next[prev] =3D next;
/* removed from list ..should add appriopriately ***/
to_add =3D curr;
prev=3Dcurr=3Dalloc->first_free;
addr_end =3D curr_offset + alloc->length[to_add];
done =3D 0;
while(curr !=3D -1)
{
if (alloc->offset[curr] =3D=3D addr_end)
{
alloc->next[to_add] =3D curr;
if (prev =3D=3D curr)
alloc->first_free =3D to_add;
else
alloc->next[prev] =3D to_add;
alloc->length[to_add] +=3D alloc->length[curr];
mlen =3D alloc->length[to_add];
alloc->length[curr] =3D 0;
done =3D 1;
break;
}
prev =3D curr;
curr =3D alloc->next[curr];
}
prev =3D curr =3D alloc->first_free;
=09
while(curr !=3D -1)
{
if (alloc->offset[curr] + alloc->length[curr] =3D=3D curr_offset)
{
/* note if done =3D 1 , already added to link list...so=20
only compactin....else shld add to llist */
if (!done) // now only adding to llist
{
alloc->next[to_add] =3D alloc->next[curr];
alloc->next[curr] =3D to_add;
}
alloc->length[curr] +=3D alloc->length[to_add];
mlen =3D alloc->length[curr];
alloc->length[to_add] =3D 0;
done =3D 1;
break;
}
curr =3D alloc->next[curr];
}
if (!done)
{
alloc->next[to_add] =3D alloc->first_free;
alloc->first_free =3D to_add;
mlen =3D alloc->length[to_add];
}
if (cnklist->max_contig_free < mlen)
cnklist->max_contig_free =3D mlen;
t2=3Dgethrtime();
printk(" free time %d",t2 - t1);
return;
}
char * my_malloc(int size)
{
return del_from_free_list(size);
}
void my_free(char * addr)
{
add_to_free_list(addr);
return ;
}
void cleanup_malloc()
{
mem_chunks * start,* next;
start =3D chk_list;
while(start)
{
kfree(start->start_addr);
next =3D start->next;
kfree(start);
start =3D next;
}
}
------_=_NextPart_000_01C0D3DA.620993E0
Content-Type: application/octet-stream;
name="mod1.c"
Content-Disposition: attachment;
filename="mod1.c"
#include <rtl.h>
#include <time.h>
#include <rtl_sched.h>
#include <pthread.h>
#include "rt_mem_mgr.h"
void * thread1(void * arg)
{
char * buff;
hrtime_t t1,t2;
struct sched_param t;
t.sched_priority = 10;
pthread_setschedparam(pthread_self(),SCHED_FIFO,&t);
pthread_make_periodic_np(pthread_self(),gethrtime(),500000000);
while(1)
{
t1 = gethrtime();
buff = del_from_free_list(100);
t2 = gethrtime();
//printk("\n Diff is %d",t2-t1);
//printk(" Addr %X",buff);
add_to_free_list(buff);
pthread_wait_np();
}
return 0;
}
pthread_t th;
static char * ch;
int init_module()
{
init_mem_mgr(1);
pthread_create(&th,0,thread1,0);
return 0;
}
void cleanup_module()
{
pthread_delete_np(th);
cleanup_malloc();
}
------_=_NextPart_000_01C0D3DA.620993E0
Content-Type: text/plain;
name="InterScan_Disclaimer.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="InterScan_Disclaimer.txt"
This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information.
If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.
Any unauthorised review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken in reliance on this e-mail is strictly
prohibited and may be unlawful.
Visit us at http://www.cognizant.com
------_=_NextPart_000_01C0D3DA.620993E0--