[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Gc.compact weirdness help



So I found my problem on the aforthmentioned problem, and I am writing here the solution just for the records.Â

reading a bit the documentation about c interfacing of ocaml, I discovered that thenÂCAMLlocal1 function registers a value variable with the gc, but is not sufficient if the function is not returingÂwith the CAMLReturn method. I think the problem is that the Gc during a compact face will try to change memory mapping and update also the value of the local variable. If this variable is in the stuck, then the gcÂwill not be able to update its value. The strange thing is the code never returned a segfault

In order to sort this problem I did the following modification in the c code:

On 17 July 2012 10:21, Haris Rotsos <cr409@xxxxxxxxxxxx> wrote:
bool
PktDemux(Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t proto,
  const Address &src, const Address &dst, NetDevice::PacketType type) {
- ÂCAMLlocal1( ml_data );
+ Âvalue ml_data; Â Â Â Â Â Â Â Â Â Â Â
+ Âcaml_register_global_root(&ml_data);

 printf("packet demux...\n");
 fprintf(stdout, "%f: receiving %u packet done...\n",
   (long)Simulator::Now().GetMicroSeconds() / 1e6, pkt->GetSize());
 fflush(stdout);

 int pkt_len = pkt->GetSize();
 ml_data = caml_alloc_string(pkt_len);
 pkt->CopyData((uint8_t *)String_val(ml_data), pkt_len);

 // find host name
 string node_name = getHostName(dev);

 //printf("node %s.%d packet\n", node_name.c_str(), dev->GetIfIndex());
 // call packet handling code in caml
 caml_callback3(*caml_named_value("demux_pkt"),
   caml_copy_string((const char *)node_name.c_str()),
   Val_int(dev->GetIfIndex()), ml_data );
 printf("packet demux end...\n");

+ Âcaml_remove_global_root(&ml_data);
Â
 return true;
}

pretty simple but pretty tricky also to know about it. I had to revert reading some source code from relevant project (basically it was a code binding of ocaml to a video codecÂlibrary) in order to figure out the solution.Â

--
Charalampos Rotsos
PhD student
The University of Cambridge
Computer Laboratory
William Gates Building
JJ Thomson Avenue
Cambridge
CB3 0FD

Phone: +44-(0) 1223 767032
Email: cr409@xxxxxxxxxxxx

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.