History

Added parallel write support to stdio. Now, both read and write operations on stdio are parallel.

shindepravin committed 16 years ago

Commit 95751f21 parent 485a8c81 file · +67 −128Browse files

Unified · Split

usr/brasil/emu/port/devtask.c+67−128
@@ -534,19 +534,19 @@ proc_splice (void *param) · 533 unmodified lines
534534
535535
536536 static void
537−remoteopen (Chan *c, int omode, char *fname, int resno )
537+remoteopen (Chan *c, int omode, char *fname, int filetype, int resno )
538538 {
539539 Conv *cv;
540540 int tmpfileuse;
541541 RemoteResource *tmprr;
542− int filetype;
542+ int stdin, stdout;
543543 RemoteFile *rf;
544544 char buff[KNAMELEN*3];
545545 Chan *tmpchan;
546546 int i;
547547
548548 cv = cmd.conv[CONV (c->qid)];
549− filetype = TYPE(c->qid) - Qdata;
549+
550550 tmpfileuse = getfileopencount (cv->rjob, filetype);
551551
552552 if ( tmpfileuse < 1) {
@@ -564,11 +564,14 @@ remoteopen (Chan *c, int omode, char *fname, int resno ) · 11 unmodified lines
564564 rf = &tmprr->remotefiles[filetype];
565565 rf->cfile = tmpchan;
566566
567− if ( (TYPE (c->qid) == Qdata) && (omode == OREAD || omode == ORDWR)){
568− /* start the reader thread */
569− if (vflag) print ("\nthread starting" );
570−// sprint (buff, "PRR[%s]", c->name->s);
571− kproc (buff, procreadremote, rf, 0 );
567+ if ((TYPE (c->qid) == Qdata)) {
568+
569+ if (omode == OREAD || omode == ORDWR) {
570+ /* start the reader thread */
571+ if (vflag) print ("\nthread starting" );
572+// sprint (buff, "PRR[%s]", c->name->s);
573+ kproc (buff, procreadremote, rf, 0 );
574+ }
572575 }
573576 tmprr = tmprr->next; /* this can be RO lock*/
574577 wunlock (&cv->rjob->l);
@@ -628,6 +631,8 @@ cmdopen (Chan *c, int omode) · 53 unmodified lines
628631 case Qenv:
629632 case Qargs:
630633 case Qns:
634+ case Qstdin:
635+ case Qstdout:
631636 error (Egreg); /* TODO: IMPLEMENT */
632637 break;
633638
@@ -661,7 +666,6 @@ cmdopen (Chan *c, int omode) · 27 unmodified lines
661666 if (vflag) print ("clone open successful [%s]\n", c->name->s);
662667 break;
663668
664− case Qstdout:
665669 case Qstatus:
666670 case Qstderr:
667671 case Qwait:
@@ -670,14 +674,7 @@ cmdopen (Chan *c, int omode) · 2 unmodified lines
670674
671675 case Qdata:
672676 case Qctl:
673− case Qstdin: /* FIXME: make sure that file is open in write only mode */
674677
675− if (TYPE(c->qid) == Qstdin ) {
676− if (omode != OWRITE ) {
677− error (Eperm);
678− }
679− }
680−
681678 qlock (&cmd.l);
682679 cv = cmd.conv[CONV (c->qid)];
683680 qlock (&cv->l);
@@ -727,16 +724,6 @@ cmdopen (Chan *c, int omode) · 43 unmodified lines
727724 }
728725 break;
729726
730− case Qstdin:
731− fname = "stdin";
732− cv->count[0]++;
733− break;
734−
735− case Qstdout:
736− fname = "stdout";
737− cv->count[1]++;
738− break;
739−
740727 case Qstderr:
741728 fname = "stderr";
742729 if(omode != OREAD)
@@ -757,8 +744,20 @@ cmdopen (Chan *c, int omode) · 14 unmodified lines
757744 fname = nil;
758745 }
759746
747+ /* do remote open when there are sub-sessions */
760748 if ( fname != nil && tmpjc > 0 ) {
761− remoteopen (c, omode, fname, tmpjc);
749+ if (TYPE(c->qid) == Qdata) {
750+ /* special case of */
751+ if(omode == OWRITE || omode == ORDWR) {
752+ /* open stdin part */
753+ remoteopen (c, omode, fname, (Qstdin-Qdata), tmpjc);
754+ }
755+ if(omode == OREAD || omode == ORDWR) {
756+ remoteopen (c, omode, fname, (Qstdout-Qdata), tmpjc);
757+ }
758+ } else {
759+ remoteopen (c, omode, fname, filetype, tmpjc);
760+ }
762761 } /* end if : fname != nil */
763762
764763 break;
@@ -862,19 +861,18 @@ closeconv (Conv *c) · 97 unmodified lines
862861 }
863862
864863 static void
865−remoteclose (Chan *c, int rjcount)
864+remoteclose (Chan *c, int filetype, int rjcount)
866865 {
867866 Conv *cc;
868867 RemoteResource *tmprr;
869868 int i;
870− int filetype;
871869 int tmpfilec;
872870
873871
874872
875873 if (vflag) print ("remote closing [%s]\n", c->name->s);
876874 cc = cmd.conv[CONV(c->qid)];
877− filetype = TYPE(c->qid) - Qdata;
875+
878876 tmpfilec = getfileopencount (cc->rjob, filetype);
879877
880878 /* close ctl files only when everything else is closed */
@@ -926,6 +924,7 @@ cmdclose (Chan *c) · 45 unmodified lines
926924 {
927925 Conv *cc;
928926 int r;
927+ int filetype;
929928 int tmpjc;
930929
931930 if ( (c->flag & COPEN) == 0)
@@ -947,7 +946,8 @@ cmdclose (Chan *c) · 15 unmodified lines
947946
948947 cc = cmd.conv[CONV (c->qid)];
949948 tmpjc = getrjobcount (cc->rjob);
950−
949+ filetype = TYPE(c->qid) - Qdata;
950+
951951 if (vflag) print ("rjobcount is [%d]\n", tmpjc);
952952 if (tmpjc < 0) {
953953 /* FIXME: you can only close status file
@@ -974,7 +974,17 @@ cmdclose (Chan *c) · 20 unmodified lines
974974
975975 if (tmpjc > 0) {
976976 /* close for remote resources also */
977− remoteclose (c, tmpjc);
977+
978+ if(TYPE(c->qid) == Qdata){
979+ if(c->mode == OWRITE || c->mode == ORDWR) {
980+ remoteclose (c, (Qstdin-Qdata), tmpjc);
981+ }
982+ if(c->mode == OREAD || c->mode == ORDWR) {
983+ remoteclose (c, (Qstdout-Qdata), tmpjc);
984+ }
985+ } else {
986+ remoteclose (c, filetype, tmpjc);
987+ }
978988 }
979989
980990 /* This code is only for CTL file */
@@ -1025,8 +1035,12 @@ readfromallasync (Chan *ch, void *a, long n, vlong offset) · 44 unmodified lines
10251035 }
10261036
10271037 if (vflag) print ("readfromallasync cname [%s]\n", ch->name->s);
1028−
1029− filetype = TYPE(ch->qid) - Qdata;
1038+
1039+ if (TYPE(ch->qid) == Qdata) {
1040+ filetype = Qstdout - Qdata;
1041+ } else {
1042+ filetype = TYPE(ch->qid) - Qdata;
1043+ }
10301044
10311045 while (1) {
10321046 rlock (&c->rjob->l);
@@ -1062,94 +1076,6 @@ readfromallasync (Chan *ch, void *a, long n, vlong offset) · 29 unmodified lines
10621076 } /* end function : readfromallasync */
10631077
10641078
1065−static long
1066−readfromallasyncold (Chan *ch, void *a, long n, vlong offset)
1067−{
1068− void *c_a;
1069− vlong c_offset;
1070− long ret, c_ret, c_n, i;
1071− Conv *c;
1072− long tmpjc;
1073− long ccount, bcount;
1074− int filetype;
1075− RemoteResource *tmprr;
1076− RemoteFile *rf;
1077−
1078− USED (offset);
1079− c = cmd.conv[CONV (ch->qid)];
1080−
1081− tmpjc = getrjobcount (c->rjob);
1082− /* making sure that remote resources are allocated */
1083− if (tmpjc < 0) {
1084− if (vflag) print ("resources not reserved\n");
1085− error (ENOReservation);
1086− }
1087−
1088− if (vflag) print ("*****readfromallasync cname [%s]\n", ch->name->s);
1089−
1090− filetype = TYPE(ch->qid) - Qdata;
1091−
1092−
1093− /* read from multiple remote files */
1094− c_a = a;
1095− c_n = n;
1096− c_offset = offset;
1097− ret = 0;
1098−
1099− while (1) {
1100−
1101− rlock (&c->rjob->l);
1102− tmprr = c->rjob->first;
1103− runlock (&c->rjob->l);
1104−
1105− ccount = 0;
1106− bcount = 0;
1107− for (i = 0 ; i < tmpjc; ++i) {
1108− rf = &tmprr->remotefiles[filetype];
1109−
1110− /* read from queue */
1111− c_ret = qconsume (rf->async_queue, c_a, c_n);
1112− if (vflag) print ("******%ldth read gave [%ld] data, state[%d]\n", i, c_ret, rf->state);
1113− if (c_ret >= 0 ) {
1114− ret = ret + c_ret;
1115− c_a = (uchar *)c_a + c_ret;
1116− c_n = c_n - c_ret;
1117− }
1118− else {
1119− if (rf->state == 2 ) {
1120− /* This thread is done */
1121− ++ccount;
1122− } else {
1123− ++bcount;
1124− }
1125−
1126− }
1127− if ( c_n <= 0 ) {
1128− break;
1129− }
1130−
1131− /* FIXME: should I lock following also in read mode ?? */
1132− tmprr = tmprr->next;
1133− } /* end for : */
1134−
1135− if (ret > 0 ) {
1136− break;
1137− }
1138−
1139− if (ccount >= tmpjc) {
1140− if (vflag) print ("----readfromallasync fileclose [%ld]\n",
1141− ccount );
1142− /* as all nodes are close, return NOW */
1143− break;
1144− }
1145− if (vflag) print ("---readfromallasync repeating with [%ld][%ld]\n", ccount, bcount);
1146−
1147− } /* end while : infinite */
1148−
1149− if (vflag) print ("******readfromallasync [%ld]\n", ret);
1150− return ret;
1151−} /* end function : readfromallasync */
1152−
11531079 static long
11541080 readfromall (Chan *ch, void *a, long n, vlong offset)
11551081 {
@@ -1172,8 +1098,13 @@ readfromall (Chan *ch, void *a, long n, vlong offset) · 16 unmodified lines
11721098 }
11731099
11741100 if (vflag) print ("readfromall cname [%s]\n", ch->name->s);
1175−
1176− filetype = TYPE(ch->qid) - Qdata;
1101+
1102+ if (TYPE(ch->qid) == Qdata) {
1103+ filetype = Qstdout - Qdata;
1104+ } else {
1105+ filetype = TYPE(ch->qid) - Qdata;
1106+ }
1107+
11771108 /* read from multiple remote files */
11781109 c_a = a;
11791110 c_n = n;
@@ -2166,7 +2097,11 @@ static long p_send2all (Chan *ch, void *a, long n, vlong offset) · 986 unmodified lines
21662097 error (ENOReservation);
21672098 }
21682099
2169− filetype = TYPE(ch->qid) - Qdata;
2100+ if (TYPE(ch->qid) == Qdata) {
2101+ filetype = Qstdin - Qdata;
2102+ } else {
2103+ filetype = TYPE(ch->qid) - Qdata;
2104+ }
21702105
21712106 /* data should be sent to all resources */
21722107 wlock (&c->rjob->l);
@@ -2256,8 +2191,12 @@ sendtoall (Chan *ch, void *a, long n, vlong offset) · 83 unmodified lines
22562191 if (vflag) print ("resources not reserved\n");
22572192 error (ENOReservation);
22582193 }
2259−
2260− filetype = TYPE(ch->qid) - Qdata;
2194+
2195+ if (TYPE(ch->qid) == Qdata) {
2196+ filetype = Qstdin - Qdata;
2197+ } else {
2198+ filetype = TYPE(ch->qid) - Qdata;
2199+ }
22612200
22622201 /* data should be sent to all resources */
22632202 rlock (&c->rjob->l);
@@ -2613,7 +2552,7 @@ cmdwrite (Chan *ch, void *a, long n, vlong offset) · 349 unmodified lines
26132552 } /* end if : local file write request */
26142553
26152554 /* sending to remote resources */
2616− return sendtoall (ch, a, n, offset);
2555+ return p_send2all (ch, a, n, offset);
26172556 } /* end switch : on filename */
26182557
26192558 return ret;