Skip to content

Commit

Permalink
Merge pull request #153 from afxgroup/profile
Browse files Browse the repository at this point in the history
Fixed profiling code
  • Loading branch information
afxgroup authored Oct 20, 2023
2 parents ab6e820 + 01fa46d commit d502888
Show file tree
Hide file tree
Showing 20 changed files with 673 additions and 321 deletions.
5 changes: 1 addition & 4 deletions GNUmakefile.os4
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ WARNINGS := \
-Wundef -Wmissing-declarations -Wunused -Wwrite-strings -Wno-unused-value -Wno-comment -Wno-missing-braces \
-Wno-deprecated-declarations -Wno-sign-compare -Wno-unused-variable -Wno-parentheses -Wno-missing-prototypes \
-Wstrict-aliasing -Wno-shadow -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing \
-Wno-type-limits -Wno-cast-function-type -Werror # -Wbad-function-cast -Wconversion -Wformat
-Wno-type-limits -Wno-cast-function-type -Wno-frame-address -Werror # -Wbad-function-cast -Wconversion -Wformat

PIC := -fPIC -DPIC
INCLUDES := -I$(LIB_DIR)/include \
Expand Down Expand Up @@ -149,7 +149,6 @@ include libc.gmk
include libm.gmk
include libamiga.gmk
include libdebug.gmk
include libprofile.gmk
include libpthread.gmk
include libcrypt.gmk
include librt.gmk
Expand Down Expand Up @@ -200,13 +199,11 @@ clean:
# Update the version numbers bound to the individual libraries
version:
$(COPY) c.lib_rev.rev amiga/amiga.lib_rev.rev
$(COPY) c.lib_rev.rev profile/profile.lib_rev.rev
$(COPY) c.lib_rev.rev math/m.lib_rev.rev
$(COPY) c.lib_rev.rev math/crypt.lib_rev.rev
$(COPY) c.lib_rev.rev math/pthread.lib_rev.rev
bumprev amiga.lib
bumprev c.lib
bumprev profile.lib
bumprev m.lib
bumprev crypt.lib
bumprev pthread.lib
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
C runtime library for AmigaOS4
runtime library for AmigaOS4

[![Build Status](https://travis-ci.com/afxgroup/clib2.svg?branch=master)](https://travis-ci.org/afxgroup/clib2)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
Expand Down
9 changes: 9 additions & 0 deletions libc.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,10 @@ C_LIBRARY := \

C_LIB := \
c.lib_rev.o \
profile/_mcount.o \
profile/profil.o \
profile/gmon.o \
profile/mcount.o \
shared_library/stubs.o \
unistd/getopt.o \
unistd/getopt_long.o
Expand Down Expand Up @@ -986,6 +990,11 @@ $(OUT_SHARED)/%.o : $(LIB_DIR)/%.c
$(VERBOSE)$(COMPILE_SHARED)
endif

$(OUT_STATIC)/profile/%.o : $(LIB_DIR)/profile/%.S
$(VERBOSE)$(COMPILE_REG)
$(OUT_SHARED)/profile/%.o : $(LIB_DIR)/profile/%.S
$(VERBOSE)$(COMPILE_REG)

$(OUTPUT_LIB)/libc.a : $(SOURCES_STATIC)
$(VERBOSE)@$(MAKELIB)
$(OUTPUT_LIB)/libc.so : $(SOURCES_SHARED)
Expand Down
57 changes: 0 additions & 57 deletions libprofile.gmk

This file was deleted.

2 changes: 1 addition & 1 deletion library/cpu/generic/bcopy.S
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

// Main entry points.

.align 5
.align 5
.global bcopy_g3

bcopy_g3: // void bcopy(const void *src, void *dst, size_t len)
Expand Down
77 changes: 51 additions & 26 deletions library/profile/_mcount.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
/*
* $Id: profile__mcount.c,v 1.0 2022-08-06 10:36:26 clib4devs Exp $
* $Id: profile__mcount.c,v 1.1 2023-10-20 10:36:26 clib4devs Exp $
*/

#include "profile_gmon.h"
#include <exec/exec.h>
#include <proto/exec.h>
#include <stddef.h>
#include <stdio.h>

#include "gmon.h"

void __mcount(uint32 frompc, uint32 selfpc);

void
__mcount(uint32 frompc, uint32 selfpc) {
uint16 *frompcindex;
struct tostruct *top, *prevtop;
struct gmonparam *p;

int32 toindex;
register ARCINDEX *frompcindex;
register struct tostruct *top, *prevtop;
register struct gmonparam *p;
register ARCINDEX toindex;
int i;

p = &_gmonparam;

Expand All @@ -34,43 +35,59 @@ __mcount(uint32 frompc, uint32 selfpc) {
if (frompc > p->textsize)
goto done;

#if (HASHFRACTION & (HASHFRACTION - 1)) == 0
if (p->hashfraction == HASHFRACTION) {
frompcindex = &p->froms[(size_t)(frompc / (HASHFRACTION *
sizeof(*p->froms)))];
} else
#endif
{
frompcindex = &p->froms[(size_t)(frompc / (p->hashfraction *
sizeof(*p->froms)))];
/* The following test used to be
if (p->log_hashfraction >= 0)
But we can simplify this if we assume the profiling data
is always initialized by the functions in gmon.c. But
then it is possible to avoid a runtime check and use the
same `if' as in gmon.c. So keep these tests in sync.
*/
if ((HASHFRACTION & (HASHFRACTION - 1)) == 0) {
/* avoid integer divide if possible: */
i = frompc >> p->log_hashfraction;
} else {
i = frompc / (p->hashfraction * sizeof(*p->froms));
}

frompcindex = &p->froms[i];
toindex = *frompcindex;

if (toindex == 0) {
/* first time down this arc */
/*
* first time traversing this arc
*/
toindex = ++p->tos[0].link;
if (toindex >= p->tolimit)
/* Ouch! Overflow */
/* halt further profiling */
goto overflow;

*frompcindex = (uint16) toindex;
*frompcindex = toindex;
top = &p->tos[toindex];
top->selfpc = selfpc;
top->count = 1;
top->link = 0;
goto done;
}

top = &p->tos[toindex];

if (top->selfpc == selfpc) {
/* arc at front of chain */
/* arc at front of chain; usual case. */
top->count++;
goto done;
}

for (;;) {
/*
* have to go looking down chain for it.
* top points to what we are looking at,
* prevtop points to previous top.
* we know it is not at the head of the chain.
*/
for (;; ) {
if (top->link == 0) {
/*
* top is end of the chain and none of the chain
* had top->selfpc == selfpc.
* so we allocate a new tostruct
* and link it to the head of the chain.
*/
toindex = ++p->tos[0].link;
if (toindex >= p->tolimit)
goto overflow;
Expand All @@ -79,17 +96,25 @@ __mcount(uint32 frompc, uint32 selfpc) {
top->selfpc = selfpc;
top->count = 1;
top->link = *frompcindex;
*frompcindex = (uint16) toindex;
*frompcindex = toindex;
goto done;
}
/*
* otherwise, check the next arc on the chain.
*/
prevtop = top;
top = &p->tos[top->link];
if (top->selfpc == selfpc) {
/*
* there it is.
* increment its count
* move it to the head of the chain.
*/
top->count++;
toindex = prevtop->link;
prevtop->link = top->link;
top->link = *frompcindex;
*frompcindex = (uint16) toindex;
*frompcindex = toindex;
goto done;
}
}
Expand Down
Loading

0 comments on commit d502888

Please sign in to comment.