Skip to content

Commit d578533

Browse files
authored
Merge pull request #204 from alfkil/beta10
Beta10 - patches to fix performance of spawnvpe+waitpid
2 parents 9855dab + dbee830 commit d578533

File tree

9 files changed

+85
-34
lines changed

9 files changed

+85
-34
lines changed

library/c.lib_rev.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define REVISION 0
33
#define SUBREVISION 0
44

5-
#define DATE "11.08.2024"
5+
#define DATE "27.08.2024"
66
#define VERS "clib4.library 1.0.0"
7-
#define VSTRING "clib4.library 1.0.0 (11.08.2024)\r\n"
8-
#define VERSTAG "\0$VER: clib4.library 1.0.0 (11.08.2024)"
7+
#define VSTRING "clib4.library 1.0.0 (27.08.2024)\r\n"
8+
#define VERSTAG "\0$VER: clib4.library 1.0.0 (27.08.2024)"

library/include/sys/wait.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ __BEGIN_DECLS
1212
#define WIFEXITED(w) (((w) & 0xff) == 0)
1313
#define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
1414
#define WIFSTOPPED(w) (((w) & 0xff) == 0x7f)
15-
#define WEXITSTATUS(w) (((w) >> 8) & 0xff)
15+
#define WEXITSTATUS(w) (((w)) & 0x000000ff)
1616
#define WTERMSIG(w) ((w) & 0x7f)
1717
#define WSTOPSIG WEXITSTATUS
1818

library/include/unistd.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ extern int spawnve(int mode, const char *path, const char **argv, char * const e
116116
extern int spawnvp(int mode, const char *path, const char **argv);
117117
/* Non standard. Used to help linux ports */
118118
extern int spawnvpe(const char *file, const char **argv, char **deltaenv, const char *dir, int fhin, int fhout, int fherr);
119-
extern int spawnvpe_callback(const char *file, const char **argv, char **deltaenv, const char *dir, int fhin, int fhout, int fherr, void (*entry_fp)(void *), void* entry_data, void (*final_fp)(int, void *), void* final_data);
120119

121120
extern int profil(unsigned short *buffer, size_t bufSize, size_t offset, unsigned int scale);
122121
extern long sysconf(int name);

library/misc/children.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ insertSpawnedChildren(uint32 pid, uint32 gid) {
3333

3434
struct Clib4Resource *res = (APTR) OpenResource(RESOURCE_NAME);
3535
if (res) {
36-
uint32 me = GetPID(0, GPID_PROCESS);
36+
uint32 parent = GetPID(0, GPID_PARENT);
3737
size_t iter = 0;
3838
void *item;
3939

@@ -44,7 +44,7 @@ insertSpawnedChildren(uint32 pid, uint32 gid) {
4444

4545
while (hashmap_iter(res->children, &iter, &item)) {
4646
const struct Clib4Node *node = item;
47-
if (node->pid == me) {
47+
if (node->pid == parent) {
4848
hashmap_set(node->spawnedProcesses, &children);
4949
break;
5050
}
@@ -126,21 +126,22 @@ void
126126
spawnedProcessExit(int32 rc, int32 data UNUSED) {
127127
struct Clib4Resource *res = (APTR) OpenResource(RESOURCE_NAME);
128128
if (res) {
129+
int32 parent = GetPID(0, GPID_PARENT);
129130
int32 me = GetPID(0, GPID_PROCESS);
130131
size_t iter = 0;
131132
void *item;
132133

133134
while (hashmap_iter(res->children, &iter, &item)) {
134135
const struct Clib4Node *node = item;
135-
if (node->pid == me) {
136+
if (node->pid == parent) {
136137
struct Clib4Children key;
137138
key.pid = me;
138139
struct Clib4Children *item = (struct Clib4Children *) hashmap_get(node->spawnedProcesses, &key);
139140
if (item != NULL) {
141+
DebugPrintF("[spawneeExit :] SUCCESS.\n");
140142
item->returnCode = rc;
141143
}
142144
}
143145
}
144146
}
145-
}
146-
147+
}

library/misc/uuid.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ static uint64_t xorshift128plus(uint64_t *s) {
1818
return s[1] + s0;
1919
}
2020

21-
void uuid4_generate(char *dst) {
21+
extern struct TimerIFace *ITimer;
22+
23+
void uuid4_generate(char *_dst) {
24+
char *dst = _dst;
2225
static const char *template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
2326
static const char *chars = "0123456789abcdef";
2427
uint64_t seed[2] = {0, 0};
2528
struct RandomState state;
2629
DECLARE_UTILITYBASE();
30+
// DECLARE_TIMERBASE();
31+
32+
33+
34+
GetSysTime((struct TimeVal *)&state);
2735

2836
typedef union {
2937
int64_t big;
@@ -70,4 +78,6 @@ void uuid4_generate(char *dst) {
7078
dst++, p++;
7179
}
7280
*dst = '\0';
81+
82+
DebugPrintF("[uuid4_generate :] result : <%s>\n", _dst);
7383
}

library/shared_library/clib4_vectors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ static void *clib4Vectors[] = {
11721172
(void *) (__get_tc_up), /* 4384 */
11731173
(void *) (__get_tc_bc), /* 4388 */
11741174

1175-
(void *) (spawnvpe_callback), /* 4392 */
1175+
(void *) (0), /* 4392 */
11761176

11771177
(void *) (sigsuspend), /* 4396 */
11781178
(void *) (spawnve), /* 4400 */

library/shared_library/interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ struct Clib4IFace {
13431343
char * (* __get_tc_up) (void); /* 4384 */
13441344
char * (* __get_tc_bc) (void); /* 4388 */
13451345

1346-
int ( *spawnvpe_callback) (const char *file, const char **argv, char **deltaenv, const char *dir, int fhin, int fhout, int fherr, void (*entry_fp)(void *), void* entry_data, void (*final_fp)(int, void *), void* final_data); /* 4392 */
1346+
int ( *spawnvpe_callback_UNUSED) (const char *file, const char **argv, char **deltaenv, const char *dir, int fhin, int fhout, int fherr, void (*entry_fp)(void *), void* entry_data, void (*final_fp)(int, void *), void* final_data); /* 4392 */
13471347

13481348
int (* sigsuspend) (const sigset_t *mask); /* 4396 */
13491349
int (* spawnve) (const char *path, const char **argv, char **deltaenv, const char *dir, int fhin, int fhout, int fherr); /* 4400 */

library/shared_library/stubs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ Clib4Call(__get_tc_ospeed, 4380);
11121112
Clib4Call(__get_tc_up, 4384);
11131113
Clib4Call(__get_tc_bc, 4388);
11141114

1115-
Clib4Call(spawnvpe_callback, 4392);
1115+
// Clib4Call(spawnvpe_callback_UNUSED, 4392);
11161116

11171117
Clib4Call(sigsuspend, 4396);
11181118
Clib4Call(spawnve, 4400);

library/unistd/spawnvpe.c

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,14 @@ get_arg_string_length(char *const argv[]) {
118118
return (result);
119119
}
120120
int
121-
spawnvpe_callback(
121+
spawnvpe(
122122
const char *file,
123123
const char **argv,
124124
char **deltaenv,
125125
const char *cwd,
126126
int fhin,
127127
int fhout,
128-
int fherr,
129-
130-
void (*entry_fp)(void *), void* entry_data,
131-
void (*final_fp)(int, void *), void* final_data
128+
int fherr
132129
) {
133130
int ret = -1;
134131
struct name_translation_info nti_name;
@@ -144,10 +141,12 @@ spawnvpe_callback(
144141
size_t parameter_string_len = 0;
145142
struct _clib4 *__clib4 = __CLIB4;
146143
struct Task *me = (struct Task *) __clib4->self;
144+
BPTR seglist;
147145

148146
__set_errno(0);
149147

150148
D(("Starting new process [%s]\n", name));
149+
// printf("[spawnvpe :] Starting new process [%s]\n", name);
151150

152151
int error = __translate_unix_to_amiga_path_name(&name, &nti_name);
153152
if (error) {
@@ -158,6 +157,12 @@ spawnvpe_callback(
158157

159158
D(("name after conversion: [%s]\n", name));
160159

160+
#if 0
161+
seglist = LoadSeg(name);
162+
if (!seglist)
163+
return -1;
164+
#endif
165+
161166
BPTR fileLock = Lock(name, SHARED_LOCK);
162167
if (fileLock) {
163168
progdirLock = ParentDir(fileLock);
@@ -200,6 +205,8 @@ spawnvpe_callback(
200205

201206
D(("File to execute: [%s]\n", finalpath));
202207

208+
// printf("[spawnvpe :] full command == <%s>\n", finalpath);
209+
203210
if (fhin >= 0) {
204211
err = __get_default_file(fhin, &fh);
205212
if (err) {
@@ -244,7 +251,51 @@ spawnvpe_callback(
244251

245252
D(("(*)Calling SystemTags.\n"));
246253

254+
// struct EntryData ed;
255+
247256
struct Task *_me = FindTask(0);
257+
#if 0
258+
struct Process *p = CreateNewProcTags(
259+
NP_Seglist, seglist,
260+
NP_FreeSeglist, TRUE,
261+
262+
NP_Cli, TRUE,
263+
NP_Child, TRUE,
264+
NP_NotifyOnDeathSigTask, _me,
265+
266+
#if 1
267+
NP_Input, iofh[0],
268+
NP_CloseInput, closefh[0],
269+
NP_Output, iofh[1],
270+
NP_CloseOutput, closefh[1],
271+
NP_Error, iofh[2],
272+
NP_CloseError, closefh[2],
273+
#else
274+
NP_Input, IDOS->Input(),
275+
NP_CloseInput, FALSE,
276+
NP_Output, IDOS->Output(),
277+
NP_CloseOutput, FALSE,
278+
NP_Error, IDOS->ErrorOutput(),
279+
NP_CloseError, FALSE,
280+
#endif
281+
282+
NP_EntryCode, spawnvpe_entryCode,
283+
NP_EntryData, &ed,
284+
285+
// NP_FinalCode, amiga_FinalCode,
286+
// NP_FinalData, fd,
287+
288+
// NP_EntryCode, spawnedProcessEnter,
289+
NP_ExitCode, spawnedProcessExit,
290+
291+
NP_Name, strdup(processName),
292+
cwdLock ? NP_CurrentDir : TAG_SKIP, cwdLock,
293+
progdirLock ? NP_ProgramDir : TAG_SKIP, progdirLock,
294+
NP_Arguments, arg_string,
295+
TAG_DONE
296+
);
297+
if (p) ret = 0;
298+
#else
248299
ret = SystemTags(finalpath,
249300
NP_NotifyOnDeathSigTask, _me,
250301
SYS_Input, iofh[0],
@@ -256,12 +307,12 @@ spawnvpe_callback(
256307
progdirLock ? NP_ProgramDir : TAG_SKIP, progdirLock,
257308
cwdLock ? NP_CurrentDir : TAG_SKIP, cwdLock,
258309
NP_Name, strdup(processName),
259-
entry_fp ? NP_EntryCode : TAG_SKIP, entry_fp,
260-
entry_data ? NP_EntryData : TAG_SKIP, entry_data,
261-
final_fp ? NP_FinalCode : TAG_SKIP, final_fp,
262-
final_data ? NP_FinalData : TAG_SKIP, final_data,
263-
NP_ExitCode, spawnedProcessExit,
310+
311+
NP_EntryCode, spawnedProcessEnter,
312+
NP_ExitCode, spawnedProcessExit,
313+
264314
TAG_DONE);
315+
#endif
265316

266317
D(("SystemTags completed. return value: [%ld]\n", ret));
267318

@@ -280,16 +331,6 @@ spawnvpe_callback(
280331
* just after SystemTags. In this case spawnv will return pid
281332
*/
282333
ret = IoErr();
283-
if (insertSpawnedChildren(ret, getgid())) {
284-
D(("Children with pid %ld and gid %ld inserted into list\n", ret, getgid()));
285-
}
286-
else {
287-
D(("Cannot insert children with pid %ld and gid %ld into list\n", ret, getgid()));
288-
}
289334
}
290-
291335
return ret;
292336
}
293-
int spawnvpe(const char *file, const char **argv, char **deltaenv, const char *dir, int fhin, int fhout, int fherr) {
294-
return spawnvpe_callback(file, argv, deltaenv, dir, fhin, fhout, fherr, 0, 0, 0, 0);
295-
}

0 commit comments

Comments
 (0)