1
0

patch-realtime 872 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649
  1. diff -Nur linux-4.4.13.orig/arch/arm/include/asm/switch_to.h linux-4.4.13/arch/arm/include/asm/switch_to.h
  2. --- linux-4.4.13.orig/arch/arm/include/asm/switch_to.h 2016-06-08 03:14:51.000000000 +0200
  3. +++ linux-4.4.13/arch/arm/include/asm/switch_to.h 2016-06-22 21:55:07.966523867 +0200
  4. @@ -3,6 +3,13 @@
  5. #include <linux/thread_info.h>
  6. +#if defined CONFIG_PREEMPT_RT_FULL && defined CONFIG_HIGHMEM
  7. +void switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p);
  8. +#else
  9. +static inline void
  10. +switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p) { }
  11. +#endif
  12. +
  13. /*
  14. * For v7 SMP cores running a preemptible kernel we may be pre-empted
  15. * during a TLB maintenance operation, so execute an inner-shareable dsb
  16. @@ -25,6 +32,7 @@
  17. #define switch_to(prev,next,last) \
  18. do { \
  19. __complete_pending_tlbi(); \
  20. + switch_kmaps(prev, next); \
  21. last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
  22. } while (0)
  23. diff -Nur linux-4.4.13.orig/arch/arm/include/asm/thread_info.h linux-4.4.13/arch/arm/include/asm/thread_info.h
  24. --- linux-4.4.13.orig/arch/arm/include/asm/thread_info.h 2016-06-08 03:14:51.000000000 +0200
  25. +++ linux-4.4.13/arch/arm/include/asm/thread_info.h 2016-06-22 21:55:07.966523867 +0200
  26. @@ -49,6 +49,7 @@
  27. struct thread_info {
  28. unsigned long flags; /* low level flags */
  29. int preempt_count; /* 0 => preemptable, <0 => bug */
  30. + int preempt_lazy_count; /* 0 => preemptable, <0 => bug */
  31. mm_segment_t addr_limit; /* address limit */
  32. struct task_struct *task; /* main task structure */
  33. __u32 cpu; /* cpu */
  34. @@ -142,7 +143,8 @@
  35. #define TIF_SYSCALL_TRACE 4 /* syscall trace active */
  36. #define TIF_SYSCALL_AUDIT 5 /* syscall auditing active */
  37. #define TIF_SYSCALL_TRACEPOINT 6 /* syscall tracepoint instrumentation */
  38. -#define TIF_SECCOMP 7 /* seccomp syscall filtering active */
  39. +#define TIF_SECCOMP 8 /* seccomp syscall filtering active */
  40. +#define TIF_NEED_RESCHED_LAZY 7
  41. #define TIF_NOHZ 12 /* in adaptive nohz mode */
  42. #define TIF_USING_IWMMXT 17
  43. @@ -152,6 +154,7 @@
  44. #define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
  45. #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  46. #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
  47. +#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)
  48. #define _TIF_UPROBE (1 << TIF_UPROBE)
  49. #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  50. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  51. @@ -167,7 +170,8 @@
  52. * Change these and you break ASM code in entry-common.S
  53. */
  54. #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
  55. - _TIF_NOTIFY_RESUME | _TIF_UPROBE)
  56. + _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
  57. + _TIF_NEED_RESCHED_LAZY)
  58. #endif /* __KERNEL__ */
  59. #endif /* __ASM_ARM_THREAD_INFO_H */
  60. diff -Nur linux-4.4.13.orig/arch/arm/Kconfig linux-4.4.13/arch/arm/Kconfig
  61. --- linux-4.4.13.orig/arch/arm/Kconfig 2016-06-08 03:14:51.000000000 +0200
  62. +++ linux-4.4.13/arch/arm/Kconfig 2016-06-22 21:55:07.966523867 +0200
  63. @@ -33,7 +33,7 @@
  64. select HARDIRQS_SW_RESEND
  65. select HAVE_ARCH_AUDITSYSCALL if (AEABI && !OABI_COMPAT)
  66. select HAVE_ARCH_BITREVERSE if (CPU_32v7M || CPU_32v7) && !CPU_32v6
  67. - select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32
  68. + select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32 && !PREEMPT_RT_BASE
  69. select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32
  70. select HAVE_ARCH_SECCOMP_FILTER if (AEABI && !OABI_COMPAT)
  71. select HAVE_ARCH_TRACEHOOK
  72. @@ -68,6 +68,7 @@
  73. select HAVE_PERF_EVENTS
  74. select HAVE_PERF_REGS
  75. select HAVE_PERF_USER_STACK_DUMP
  76. + select HAVE_PREEMPT_LAZY
  77. select HAVE_RCU_TABLE_FREE if (SMP && ARM_LPAE)
  78. select HAVE_REGS_AND_STACK_ACCESS_API
  79. select HAVE_SYSCALL_TRACEPOINTS
  80. diff -Nur linux-4.4.13.orig/arch/arm/kernel/asm-offsets.c linux-4.4.13/arch/arm/kernel/asm-offsets.c
  81. --- linux-4.4.13.orig/arch/arm/kernel/asm-offsets.c 2016-06-08 03:14:51.000000000 +0200
  82. +++ linux-4.4.13/arch/arm/kernel/asm-offsets.c 2016-06-22 21:55:07.970523867 +0200
  83. @@ -65,6 +65,7 @@
  84. BLANK();
  85. DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
  86. DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
  87. + DEFINE(TI_PREEMPT_LAZY, offsetof(struct thread_info, preempt_lazy_count));
  88. DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit));
  89. DEFINE(TI_TASK, offsetof(struct thread_info, task));
  90. DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  91. diff -Nur linux-4.4.13.orig/arch/arm/kernel/entry-armv.S linux-4.4.13/arch/arm/kernel/entry-armv.S
  92. --- linux-4.4.13.orig/arch/arm/kernel/entry-armv.S 2016-06-08 03:14:51.000000000 +0200
  93. +++ linux-4.4.13/arch/arm/kernel/entry-armv.S 2016-06-22 21:55:07.970523867 +0200
  94. @@ -215,11 +215,18 @@
  95. #ifdef CONFIG_PREEMPT
  96. get_thread_info tsk
  97. ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
  98. - ldr r0, [tsk, #TI_FLAGS] @ get flags
  99. teq r8, #0 @ if preempt count != 0
  100. + bne 1f @ return from exeption
  101. + ldr r0, [tsk, #TI_FLAGS] @ get flags
  102. + tst r0, #_TIF_NEED_RESCHED @ if NEED_RESCHED is set
  103. + blne svc_preempt @ preempt!
  104. +
  105. + ldr r8, [tsk, #TI_PREEMPT_LAZY] @ get preempt lazy count
  106. + teq r8, #0 @ if preempt lazy count != 0
  107. movne r0, #0 @ force flags to 0
  108. - tst r0, #_TIF_NEED_RESCHED
  109. + tst r0, #_TIF_NEED_RESCHED_LAZY
  110. blne svc_preempt
  111. +1:
  112. #endif
  113. svc_exit r5, irq = 1 @ return from exception
  114. @@ -234,8 +241,14 @@
  115. 1: bl preempt_schedule_irq @ irq en/disable is done inside
  116. ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
  117. tst r0, #_TIF_NEED_RESCHED
  118. + bne 1b
  119. + tst r0, #_TIF_NEED_RESCHED_LAZY
  120. reteq r8 @ go again
  121. - b 1b
  122. + ldr r0, [tsk, #TI_PREEMPT_LAZY] @ get preempt lazy count
  123. + teq r0, #0 @ if preempt lazy count != 0
  124. + beq 1b
  125. + ret r8 @ go again
  126. +
  127. #endif
  128. __und_fault:
  129. diff -Nur linux-4.4.13.orig/arch/arm/kernel/entry-common.S linux-4.4.13/arch/arm/kernel/entry-common.S
  130. --- linux-4.4.13.orig/arch/arm/kernel/entry-common.S 2016-06-08 03:14:51.000000000 +0200
  131. +++ linux-4.4.13/arch/arm/kernel/entry-common.S 2016-06-22 21:55:07.970523867 +0200
  132. @@ -36,7 +36,9 @@
  133. UNWIND(.cantunwind )
  134. disable_irq_notrace @ disable interrupts
  135. ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
  136. - tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
  137. + tst r1, #((_TIF_SYSCALL_WORK | _TIF_WORK_MASK) & ~_TIF_SECCOMP)
  138. + bne fast_work_pending
  139. + tst r1, #_TIF_SECCOMP
  140. bne fast_work_pending
  141. /* perform architecture specific actions before user return */
  142. @@ -62,8 +64,11 @@
  143. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  144. disable_irq_notrace @ disable interrupts
  145. ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
  146. - tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
  147. + tst r1, #((_TIF_SYSCALL_WORK | _TIF_WORK_MASK) & ~_TIF_SECCOMP)
  148. + bne do_slower_path
  149. + tst r1, #_TIF_SECCOMP
  150. beq no_work_pending
  151. +do_slower_path:
  152. UNWIND(.fnend )
  153. ENDPROC(ret_fast_syscall)
  154. diff -Nur linux-4.4.13.orig/arch/arm/kernel/process.c linux-4.4.13/arch/arm/kernel/process.c
  155. --- linux-4.4.13.orig/arch/arm/kernel/process.c 2016-06-08 03:14:51.000000000 +0200
  156. +++ linux-4.4.13/arch/arm/kernel/process.c 2016-06-22 21:55:07.970523867 +0200
  157. @@ -319,6 +319,30 @@
  158. }
  159. #ifdef CONFIG_MMU
  160. +/*
  161. + * CONFIG_SPLIT_PTLOCK_CPUS results in a page->ptl lock. If the lock is not
  162. + * initialized by pgtable_page_ctor() then a coredump of the vector page will
  163. + * fail.
  164. + */
  165. +static int __init vectors_user_mapping_init_page(void)
  166. +{
  167. + struct page *page;
  168. + unsigned long addr = 0xffff0000;
  169. + pgd_t *pgd;
  170. + pud_t *pud;
  171. + pmd_t *pmd;
  172. +
  173. + pgd = pgd_offset_k(addr);
  174. + pud = pud_offset(pgd, addr);
  175. + pmd = pmd_offset(pud, addr);
  176. + page = pmd_page(*(pmd));
  177. +
  178. + pgtable_page_ctor(page);
  179. +
  180. + return 0;
  181. +}
  182. +late_initcall(vectors_user_mapping_init_page);
  183. +
  184. #ifdef CONFIG_KUSER_HELPERS
  185. /*
  186. * The vectors page is always readable from user space for the
  187. diff -Nur linux-4.4.13.orig/arch/arm/kernel/signal.c linux-4.4.13/arch/arm/kernel/signal.c
  188. --- linux-4.4.13.orig/arch/arm/kernel/signal.c 2016-06-08 03:14:51.000000000 +0200
  189. +++ linux-4.4.13/arch/arm/kernel/signal.c 2016-06-22 21:55:07.970523867 +0200
  190. @@ -572,7 +572,8 @@
  191. */
  192. trace_hardirqs_off();
  193. do {
  194. - if (likely(thread_flags & _TIF_NEED_RESCHED)) {
  195. + if (likely(thread_flags & (_TIF_NEED_RESCHED |
  196. + _TIF_NEED_RESCHED_LAZY))) {
  197. schedule();
  198. } else {
  199. if (unlikely(!user_mode(regs)))
  200. diff -Nur linux-4.4.13.orig/arch/arm/kernel/smp.c linux-4.4.13/arch/arm/kernel/smp.c
  201. --- linux-4.4.13.orig/arch/arm/kernel/smp.c 2016-06-08 03:14:51.000000000 +0200
  202. +++ linux-4.4.13/arch/arm/kernel/smp.c 2016-06-22 21:55:07.974523867 +0200
  203. @@ -230,8 +230,6 @@
  204. flush_cache_louis();
  205. local_flush_tlb_all();
  206. - clear_tasks_mm_cpumask(cpu);
  207. -
  208. return 0;
  209. }
  210. @@ -247,6 +245,9 @@
  211. pr_err("CPU%u: cpu didn't die\n", cpu);
  212. return;
  213. }
  214. +
  215. + clear_tasks_mm_cpumask(cpu);
  216. +
  217. pr_notice("CPU%u: shutdown\n", cpu);
  218. /*
  219. diff -Nur linux-4.4.13.orig/arch/arm/kernel/unwind.c linux-4.4.13/arch/arm/kernel/unwind.c
  220. --- linux-4.4.13.orig/arch/arm/kernel/unwind.c 2016-06-08 03:14:51.000000000 +0200
  221. +++ linux-4.4.13/arch/arm/kernel/unwind.c 2016-06-22 21:55:07.974523867 +0200
  222. @@ -93,7 +93,7 @@
  223. static const struct unwind_idx *__origin_unwind_idx;
  224. extern const struct unwind_idx __stop_unwind_idx[];
  225. -static DEFINE_SPINLOCK(unwind_lock);
  226. +static DEFINE_RAW_SPINLOCK(unwind_lock);
  227. static LIST_HEAD(unwind_tables);
  228. /* Convert a prel31 symbol to an absolute address */
  229. @@ -201,7 +201,7 @@
  230. /* module unwind tables */
  231. struct unwind_table *table;
  232. - spin_lock_irqsave(&unwind_lock, flags);
  233. + raw_spin_lock_irqsave(&unwind_lock, flags);
  234. list_for_each_entry(table, &unwind_tables, list) {
  235. if (addr >= table->begin_addr &&
  236. addr < table->end_addr) {
  237. @@ -213,7 +213,7 @@
  238. break;
  239. }
  240. }
  241. - spin_unlock_irqrestore(&unwind_lock, flags);
  242. + raw_spin_unlock_irqrestore(&unwind_lock, flags);
  243. }
  244. pr_debug("%s: idx = %p\n", __func__, idx);
  245. @@ -529,9 +529,9 @@
  246. tab->begin_addr = text_addr;
  247. tab->end_addr = text_addr + text_size;
  248. - spin_lock_irqsave(&unwind_lock, flags);
  249. + raw_spin_lock_irqsave(&unwind_lock, flags);
  250. list_add_tail(&tab->list, &unwind_tables);
  251. - spin_unlock_irqrestore(&unwind_lock, flags);
  252. + raw_spin_unlock_irqrestore(&unwind_lock, flags);
  253. return tab;
  254. }
  255. @@ -543,9 +543,9 @@
  256. if (!tab)
  257. return;
  258. - spin_lock_irqsave(&unwind_lock, flags);
  259. + raw_spin_lock_irqsave(&unwind_lock, flags);
  260. list_del(&tab->list);
  261. - spin_unlock_irqrestore(&unwind_lock, flags);
  262. + raw_spin_unlock_irqrestore(&unwind_lock, flags);
  263. kfree(tab);
  264. }
  265. diff -Nur linux-4.4.13.orig/arch/arm/kvm/arm.c linux-4.4.13/arch/arm/kvm/arm.c
  266. --- linux-4.4.13.orig/arch/arm/kvm/arm.c 2016-06-08 03:14:51.000000000 +0200
  267. +++ linux-4.4.13/arch/arm/kvm/arm.c 2016-06-22 21:55:07.974523867 +0200
  268. @@ -498,18 +498,18 @@
  269. struct kvm_vcpu *vcpu;
  270. kvm_for_each_vcpu(i, vcpu, kvm) {
  271. - wait_queue_head_t *wq = kvm_arch_vcpu_wq(vcpu);
  272. + struct swait_queue_head *wq = kvm_arch_vcpu_wq(vcpu);
  273. vcpu->arch.pause = false;
  274. - wake_up_interruptible(wq);
  275. + swake_up(wq);
  276. }
  277. }
  278. static void vcpu_sleep(struct kvm_vcpu *vcpu)
  279. {
  280. - wait_queue_head_t *wq = kvm_arch_vcpu_wq(vcpu);
  281. + struct swait_queue_head *wq = kvm_arch_vcpu_wq(vcpu);
  282. - wait_event_interruptible(*wq, ((!vcpu->arch.power_off) &&
  283. + swait_event_interruptible(*wq, ((!vcpu->arch.power_off) &&
  284. (!vcpu->arch.pause)));
  285. }
  286. @@ -568,7 +568,7 @@
  287. * involves poking the GIC, which must be done in a
  288. * non-preemptible context.
  289. */
  290. - preempt_disable();
  291. + migrate_disable();
  292. kvm_timer_flush_hwstate(vcpu);
  293. kvm_vgic_flush_hwstate(vcpu);
  294. @@ -587,7 +587,7 @@
  295. local_irq_enable();
  296. kvm_timer_sync_hwstate(vcpu);
  297. kvm_vgic_sync_hwstate(vcpu);
  298. - preempt_enable();
  299. + migrate_enable();
  300. continue;
  301. }
  302. @@ -641,7 +641,7 @@
  303. kvm_vgic_sync_hwstate(vcpu);
  304. - preempt_enable();
  305. + migrate_enable();
  306. ret = handle_exit(vcpu, run, ret);
  307. }
  308. diff -Nur linux-4.4.13.orig/arch/arm/kvm/psci.c linux-4.4.13/arch/arm/kvm/psci.c
  309. --- linux-4.4.13.orig/arch/arm/kvm/psci.c 2016-06-08 03:14:51.000000000 +0200
  310. +++ linux-4.4.13/arch/arm/kvm/psci.c 2016-06-22 21:55:07.974523867 +0200
  311. @@ -70,7 +70,7 @@
  312. {
  313. struct kvm *kvm = source_vcpu->kvm;
  314. struct kvm_vcpu *vcpu = NULL;
  315. - wait_queue_head_t *wq;
  316. + struct swait_queue_head *wq;
  317. unsigned long cpu_id;
  318. unsigned long context_id;
  319. phys_addr_t target_pc;
  320. @@ -119,7 +119,7 @@
  321. smp_mb(); /* Make sure the above is visible */
  322. wq = kvm_arch_vcpu_wq(vcpu);
  323. - wake_up_interruptible(wq);
  324. + swake_up(wq);
  325. return PSCI_RET_SUCCESS;
  326. }
  327. diff -Nur linux-4.4.13.orig/arch/arm/mach-at91/at91rm9200.c linux-4.4.13/arch/arm/mach-at91/at91rm9200.c
  328. --- linux-4.4.13.orig/arch/arm/mach-at91/at91rm9200.c 2016-06-08 03:14:51.000000000 +0200
  329. +++ linux-4.4.13/arch/arm/mach-at91/at91rm9200.c 2016-06-22 21:55:07.974523867 +0200
  330. @@ -12,7 +12,6 @@
  331. #include <linux/of_platform.h>
  332. #include <asm/mach/arch.h>
  333. -#include <asm/system_misc.h>
  334. #include "generic.h"
  335. #include "soc.h"
  336. @@ -33,7 +32,6 @@
  337. of_platform_populate(NULL, of_default_bus_match_table, NULL, soc_dev);
  338. - arm_pm_idle = at91rm9200_idle;
  339. at91rm9200_pm_init();
  340. }
  341. diff -Nur linux-4.4.13.orig/arch/arm/mach-at91/at91sam9.c linux-4.4.13/arch/arm/mach-at91/at91sam9.c
  342. --- linux-4.4.13.orig/arch/arm/mach-at91/at91sam9.c 2016-06-08 03:14:51.000000000 +0200
  343. +++ linux-4.4.13/arch/arm/mach-at91/at91sam9.c 2016-06-22 21:55:07.974523867 +0200
  344. @@ -62,8 +62,6 @@
  345. soc_dev = soc_device_to_device(soc);
  346. of_platform_populate(NULL, of_default_bus_match_table, NULL, soc_dev);
  347. -
  348. - arm_pm_idle = at91sam9_idle;
  349. }
  350. static void __init at91sam9_dt_device_init(void)
  351. diff -Nur linux-4.4.13.orig/arch/arm/mach-at91/generic.h linux-4.4.13/arch/arm/mach-at91/generic.h
  352. --- linux-4.4.13.orig/arch/arm/mach-at91/generic.h 2016-06-08 03:14:51.000000000 +0200
  353. +++ linux-4.4.13/arch/arm/mach-at91/generic.h 2016-06-22 21:55:07.974523867 +0200
  354. @@ -11,27 +11,18 @@
  355. #ifndef _AT91_GENERIC_H
  356. #define _AT91_GENERIC_H
  357. -#include <linux/of.h>
  358. -#include <linux/reboot.h>
  359. -
  360. - /* Map io */
  361. -extern void __init at91_map_io(void);
  362. -extern void __init at91_alt_map_io(void);
  363. -
  364. -/* idle */
  365. -extern void at91rm9200_idle(void);
  366. -extern void at91sam9_idle(void);
  367. -
  368. #ifdef CONFIG_PM
  369. extern void __init at91rm9200_pm_init(void);
  370. extern void __init at91sam9260_pm_init(void);
  371. extern void __init at91sam9g45_pm_init(void);
  372. extern void __init at91sam9x5_pm_init(void);
  373. +extern void __init sama5_pm_init(void);
  374. #else
  375. static inline void __init at91rm9200_pm_init(void) { }
  376. static inline void __init at91sam9260_pm_init(void) { }
  377. static inline void __init at91sam9g45_pm_init(void) { }
  378. static inline void __init at91sam9x5_pm_init(void) { }
  379. +static inline void __init sama5_pm_init(void) { }
  380. #endif
  381. #endif /* _AT91_GENERIC_H */
  382. diff -Nur linux-4.4.13.orig/arch/arm/mach-at91/Kconfig linux-4.4.13/arch/arm/mach-at91/Kconfig
  383. --- linux-4.4.13.orig/arch/arm/mach-at91/Kconfig 2016-06-08 03:14:51.000000000 +0200
  384. +++ linux-4.4.13/arch/arm/mach-at91/Kconfig 2016-06-22 21:55:07.974523867 +0200
  385. @@ -99,6 +99,7 @@
  386. config COMMON_CLK_AT91
  387. bool
  388. select COMMON_CLK
  389. + select MFD_SYSCON
  390. config HAVE_AT91_SMD
  391. bool
  392. diff -Nur linux-4.4.13.orig/arch/arm/mach-at91/pm.c linux-4.4.13/arch/arm/mach-at91/pm.c
  393. --- linux-4.4.13.orig/arch/arm/mach-at91/pm.c 2016-06-08 03:14:51.000000000 +0200
  394. +++ linux-4.4.13/arch/arm/mach-at91/pm.c 2016-06-22 21:55:07.974523867 +0200
  395. @@ -31,10 +31,13 @@
  396. #include <asm/mach/irq.h>
  397. #include <asm/fncpy.h>
  398. #include <asm/cacheflush.h>
  399. +#include <asm/system_misc.h>
  400. #include "generic.h"
  401. #include "pm.h"
  402. +static void __iomem *pmc;
  403. +
  404. /*
  405. * FIXME: this is needed to communicate between the pinctrl driver and
  406. * the PM implementation in the machine. Possibly part of the PM
  407. @@ -87,7 +90,7 @@
  408. unsigned long scsr;
  409. int i;
  410. - scsr = at91_pmc_read(AT91_PMC_SCSR);
  411. + scsr = readl(pmc + AT91_PMC_SCSR);
  412. /* USB must not be using PLLB */
  413. if ((scsr & at91_pm_data.uhp_udp_mask) != 0) {
  414. @@ -101,8 +104,7 @@
  415. if ((scsr & (AT91_PMC_PCK0 << i)) == 0)
  416. continue;
  417. -
  418. - css = at91_pmc_read(AT91_PMC_PCKR(i)) & AT91_PMC_CSS;
  419. + css = readl(pmc + AT91_PMC_PCKR(i)) & AT91_PMC_CSS;
  420. if (css != AT91_PMC_CSS_SLOW) {
  421. pr_err("AT91: PM - Suspend-to-RAM with PCK%d src %d\n", i, css);
  422. return 0;
  423. @@ -145,8 +147,8 @@
  424. flush_cache_all();
  425. outer_disable();
  426. - at91_suspend_sram_fn(at91_pmc_base, at91_ramc_base[0],
  427. - at91_ramc_base[1], pm_data);
  428. + at91_suspend_sram_fn(pmc, at91_ramc_base[0],
  429. + at91_ramc_base[1], pm_data);
  430. outer_resume();
  431. }
  432. @@ -353,6 +355,21 @@
  433. at91_pm_set_standby(standby);
  434. }
  435. +void at91rm9200_idle(void)
  436. +{
  437. + /*
  438. + * Disable the processor clock. The processor will be automatically
  439. + * re-enabled by an interrupt or by a reset.
  440. + */
  441. + writel(AT91_PMC_PCK, pmc + AT91_PMC_SCDR);
  442. +}
  443. +
  444. +void at91sam9_idle(void)
  445. +{
  446. + writel(AT91_PMC_PCK, pmc + AT91_PMC_SCDR);
  447. + cpu_do_idle();
  448. +}
  449. +
  450. static void __init at91_pm_sram_init(void)
  451. {
  452. struct gen_pool *sram_pool;
  453. @@ -399,13 +416,36 @@
  454. &at91_pm_suspend_in_sram, at91_pm_suspend_in_sram_sz);
  455. }
  456. -static void __init at91_pm_init(void)
  457. +static const struct of_device_id atmel_pmc_ids[] __initconst = {
  458. + { .compatible = "atmel,at91rm9200-pmc" },
  459. + { .compatible = "atmel,at91sam9260-pmc" },
  460. + { .compatible = "atmel,at91sam9g45-pmc" },
  461. + { .compatible = "atmel,at91sam9n12-pmc" },
  462. + { .compatible = "atmel,at91sam9x5-pmc" },
  463. + { .compatible = "atmel,sama5d3-pmc" },
  464. + { .compatible = "atmel,sama5d2-pmc" },
  465. + { /* sentinel */ },
  466. +};
  467. +
  468. +static void __init at91_pm_init(void (*pm_idle)(void))
  469. {
  470. - at91_pm_sram_init();
  471. + struct device_node *pmc_np;
  472. if (at91_cpuidle_device.dev.platform_data)
  473. platform_device_register(&at91_cpuidle_device);
  474. + pmc_np = of_find_matching_node(NULL, atmel_pmc_ids);
  475. + pmc = of_iomap(pmc_np, 0);
  476. + if (!pmc) {
  477. + pr_err("AT91: PM not supported, PMC not found\n");
  478. + return;
  479. + }
  480. +
  481. + if (pm_idle)
  482. + arm_pm_idle = pm_idle;
  483. +
  484. + at91_pm_sram_init();
  485. +
  486. if (at91_suspend_sram_fn)
  487. suspend_set_ops(&at91_pm_ops);
  488. else
  489. @@ -424,7 +464,7 @@
  490. at91_pm_data.uhp_udp_mask = AT91RM9200_PMC_UHP | AT91RM9200_PMC_UDP;
  491. at91_pm_data.memctrl = AT91_MEMCTRL_MC;
  492. - at91_pm_init();
  493. + at91_pm_init(at91rm9200_idle);
  494. }
  495. void __init at91sam9260_pm_init(void)
  496. @@ -432,7 +472,7 @@
  497. at91_dt_ramc();
  498. at91_pm_data.memctrl = AT91_MEMCTRL_SDRAMC;
  499. at91_pm_data.uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP;
  500. - return at91_pm_init();
  501. + at91_pm_init(at91sam9_idle);
  502. }
  503. void __init at91sam9g45_pm_init(void)
  504. @@ -440,7 +480,7 @@
  505. at91_dt_ramc();
  506. at91_pm_data.uhp_udp_mask = AT91SAM926x_PMC_UHP;
  507. at91_pm_data.memctrl = AT91_MEMCTRL_DDRSDR;
  508. - return at91_pm_init();
  509. + at91_pm_init(at91sam9_idle);
  510. }
  511. void __init at91sam9x5_pm_init(void)
  512. @@ -448,5 +488,13 @@
  513. at91_dt_ramc();
  514. at91_pm_data.uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP;
  515. at91_pm_data.memctrl = AT91_MEMCTRL_DDRSDR;
  516. - return at91_pm_init();
  517. + at91_pm_init(at91sam9_idle);
  518. +}
  519. +
  520. +void __init sama5_pm_init(void)
  521. +{
  522. + at91_dt_ramc();
  523. + at91_pm_data.uhp_udp_mask = AT91SAM926x_PMC_UHP | AT91SAM926x_PMC_UDP;
  524. + at91_pm_data.memctrl = AT91_MEMCTRL_DDRSDR;
  525. + at91_pm_init(NULL);
  526. }
  527. diff -Nur linux-4.4.13.orig/arch/arm/mach-at91/sama5.c linux-4.4.13/arch/arm/mach-at91/sama5.c
  528. --- linux-4.4.13.orig/arch/arm/mach-at91/sama5.c 2016-06-08 03:14:51.000000000 +0200
  529. +++ linux-4.4.13/arch/arm/mach-at91/sama5.c 2016-06-22 21:55:07.974523867 +0200
  530. @@ -51,7 +51,7 @@
  531. soc_dev = soc_device_to_device(soc);
  532. of_platform_populate(NULL, of_default_bus_match_table, NULL, soc_dev);
  533. - at91sam9x5_pm_init();
  534. + sama5_pm_init();
  535. }
  536. static const char *const sama5_dt_board_compat[] __initconst = {
  537. diff -Nur linux-4.4.13.orig/arch/arm/mach-exynos/platsmp.c linux-4.4.13/arch/arm/mach-exynos/platsmp.c
  538. --- linux-4.4.13.orig/arch/arm/mach-exynos/platsmp.c 2016-06-08 03:14:51.000000000 +0200
  539. +++ linux-4.4.13/arch/arm/mach-exynos/platsmp.c 2016-06-22 21:55:07.974523867 +0200
  540. @@ -230,7 +230,7 @@
  541. return (void __iomem *)(S5P_VA_SCU);
  542. }
  543. -static DEFINE_SPINLOCK(boot_lock);
  544. +static DEFINE_RAW_SPINLOCK(boot_lock);
  545. static void exynos_secondary_init(unsigned int cpu)
  546. {
  547. @@ -243,8 +243,8 @@
  548. /*
  549. * Synchronise with the boot thread.
  550. */
  551. - spin_lock(&boot_lock);
  552. - spin_unlock(&boot_lock);
  553. + raw_spin_lock(&boot_lock);
  554. + raw_spin_unlock(&boot_lock);
  555. }
  556. int exynos_set_boot_addr(u32 core_id, unsigned long boot_addr)
  557. @@ -308,7 +308,7 @@
  558. * Set synchronisation state between this boot processor
  559. * and the secondary one
  560. */
  561. - spin_lock(&boot_lock);
  562. + raw_spin_lock(&boot_lock);
  563. /*
  564. * The secondary processor is waiting to be released from
  565. @@ -335,7 +335,7 @@
  566. if (timeout == 0) {
  567. printk(KERN_ERR "cpu1 power enable failed");
  568. - spin_unlock(&boot_lock);
  569. + raw_spin_unlock(&boot_lock);
  570. return -ETIMEDOUT;
  571. }
  572. }
  573. @@ -381,7 +381,7 @@
  574. * calibrations, then wait for it to finish
  575. */
  576. fail:
  577. - spin_unlock(&boot_lock);
  578. + raw_spin_unlock(&boot_lock);
  579. return pen_release != -1 ? ret : 0;
  580. }
  581. diff -Nur linux-4.4.13.orig/arch/arm/mach-hisi/platmcpm.c linux-4.4.13/arch/arm/mach-hisi/platmcpm.c
  582. --- linux-4.4.13.orig/arch/arm/mach-hisi/platmcpm.c 2016-06-08 03:14:51.000000000 +0200
  583. +++ linux-4.4.13/arch/arm/mach-hisi/platmcpm.c 2016-06-22 21:55:07.974523867 +0200
  584. @@ -61,7 +61,7 @@
  585. static void __iomem *sysctrl, *fabric;
  586. static int hip04_cpu_table[HIP04_MAX_CLUSTERS][HIP04_MAX_CPUS_PER_CLUSTER];
  587. -static DEFINE_SPINLOCK(boot_lock);
  588. +static DEFINE_RAW_SPINLOCK(boot_lock);
  589. static u32 fabric_phys_addr;
  590. /*
  591. * [0]: bootwrapper physical address
  592. @@ -113,7 +113,7 @@
  593. if (cluster >= HIP04_MAX_CLUSTERS || cpu >= HIP04_MAX_CPUS_PER_CLUSTER)
  594. return -EINVAL;
  595. - spin_lock_irq(&boot_lock);
  596. + raw_spin_lock_irq(&boot_lock);
  597. if (hip04_cpu_table[cluster][cpu])
  598. goto out;
  599. @@ -147,7 +147,7 @@
  600. out:
  601. hip04_cpu_table[cluster][cpu]++;
  602. - spin_unlock_irq(&boot_lock);
  603. + raw_spin_unlock_irq(&boot_lock);
  604. return 0;
  605. }
  606. @@ -162,11 +162,11 @@
  607. cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  608. cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  609. - spin_lock(&boot_lock);
  610. + raw_spin_lock(&boot_lock);
  611. hip04_cpu_table[cluster][cpu]--;
  612. if (hip04_cpu_table[cluster][cpu] == 1) {
  613. /* A power_up request went ahead of us. */
  614. - spin_unlock(&boot_lock);
  615. + raw_spin_unlock(&boot_lock);
  616. return;
  617. } else if (hip04_cpu_table[cluster][cpu] > 1) {
  618. pr_err("Cluster %d CPU%d boots multiple times\n", cluster, cpu);
  619. @@ -174,7 +174,7 @@
  620. }
  621. last_man = hip04_cluster_is_down(cluster);
  622. - spin_unlock(&boot_lock);
  623. + raw_spin_unlock(&boot_lock);
  624. if (last_man) {
  625. /* Since it's Cortex A15, disable L2 prefetching. */
  626. asm volatile(
  627. @@ -203,7 +203,7 @@
  628. cpu >= HIP04_MAX_CPUS_PER_CLUSTER);
  629. count = TIMEOUT_MSEC / POLL_MSEC;
  630. - spin_lock_irq(&boot_lock);
  631. + raw_spin_lock_irq(&boot_lock);
  632. for (tries = 0; tries < count; tries++) {
  633. if (hip04_cpu_table[cluster][cpu])
  634. goto err;
  635. @@ -211,10 +211,10 @@
  636. data = readl_relaxed(sysctrl + SC_CPU_RESET_STATUS(cluster));
  637. if (data & CORE_WFI_STATUS(cpu))
  638. break;
  639. - spin_unlock_irq(&boot_lock);
  640. + raw_spin_unlock_irq(&boot_lock);
  641. /* Wait for clean L2 when the whole cluster is down. */
  642. msleep(POLL_MSEC);
  643. - spin_lock_irq(&boot_lock);
  644. + raw_spin_lock_irq(&boot_lock);
  645. }
  646. if (tries >= count)
  647. goto err;
  648. @@ -231,10 +231,10 @@
  649. goto err;
  650. if (hip04_cluster_is_down(cluster))
  651. hip04_set_snoop_filter(cluster, 0);
  652. - spin_unlock_irq(&boot_lock);
  653. + raw_spin_unlock_irq(&boot_lock);
  654. return 1;
  655. err:
  656. - spin_unlock_irq(&boot_lock);
  657. + raw_spin_unlock_irq(&boot_lock);
  658. return 0;
  659. }
  660. #endif
  661. diff -Nur linux-4.4.13.orig/arch/arm/mach-imx/Kconfig linux-4.4.13/arch/arm/mach-imx/Kconfig
  662. --- linux-4.4.13.orig/arch/arm/mach-imx/Kconfig 2016-06-08 03:14:51.000000000 +0200
  663. +++ linux-4.4.13/arch/arm/mach-imx/Kconfig 2016-06-22 21:55:07.974523867 +0200
  664. @@ -524,7 +524,7 @@
  665. bool "i.MX6 Quad/DualLite support"
  666. select ARM_ERRATA_764369 if SMP
  667. select HAVE_ARM_SCU if SMP
  668. - select HAVE_ARM_TWD if SMP
  669. + select HAVE_ARM_TWD
  670. select PCI_DOMAINS if PCI
  671. select PINCTRL_IMX6Q
  672. select SOC_IMX6
  673. diff -Nur linux-4.4.13.orig/arch/arm/mach-omap2/omap-smp.c linux-4.4.13/arch/arm/mach-omap2/omap-smp.c
  674. --- linux-4.4.13.orig/arch/arm/mach-omap2/omap-smp.c 2016-06-08 03:14:51.000000000 +0200
  675. +++ linux-4.4.13/arch/arm/mach-omap2/omap-smp.c 2016-06-22 21:55:07.974523867 +0200
  676. @@ -43,7 +43,7 @@
  677. /* SCU base address */
  678. static void __iomem *scu_base;
  679. -static DEFINE_SPINLOCK(boot_lock);
  680. +static DEFINE_RAW_SPINLOCK(boot_lock);
  681. void __iomem *omap4_get_scu_base(void)
  682. {
  683. @@ -74,8 +74,8 @@
  684. /*
  685. * Synchronise with the boot thread.
  686. */
  687. - spin_lock(&boot_lock);
  688. - spin_unlock(&boot_lock);
  689. + raw_spin_lock(&boot_lock);
  690. + raw_spin_unlock(&boot_lock);
  691. }
  692. static int omap4_boot_secondary(unsigned int cpu, struct task_struct *idle)
  693. @@ -89,7 +89,7 @@
  694. * Set synchronisation state between this boot processor
  695. * and the secondary one
  696. */
  697. - spin_lock(&boot_lock);
  698. + raw_spin_lock(&boot_lock);
  699. /*
  700. * Update the AuxCoreBoot0 with boot state for secondary core.
  701. @@ -166,7 +166,7 @@
  702. * Now the secondary core is starting up let it run its
  703. * calibrations, then wait for it to finish
  704. */
  705. - spin_unlock(&boot_lock);
  706. + raw_spin_unlock(&boot_lock);
  707. return 0;
  708. }
  709. diff -Nur linux-4.4.13.orig/arch/arm/mach-prima2/platsmp.c linux-4.4.13/arch/arm/mach-prima2/platsmp.c
  710. --- linux-4.4.13.orig/arch/arm/mach-prima2/platsmp.c 2016-06-08 03:14:51.000000000 +0200
  711. +++ linux-4.4.13/arch/arm/mach-prima2/platsmp.c 2016-06-22 21:55:07.974523867 +0200
  712. @@ -22,7 +22,7 @@
  713. static void __iomem *clk_base;
  714. -static DEFINE_SPINLOCK(boot_lock);
  715. +static DEFINE_RAW_SPINLOCK(boot_lock);
  716. static void sirfsoc_secondary_init(unsigned int cpu)
  717. {
  718. @@ -36,8 +36,8 @@
  719. /*
  720. * Synchronise with the boot thread.
  721. */
  722. - spin_lock(&boot_lock);
  723. - spin_unlock(&boot_lock);
  724. + raw_spin_lock(&boot_lock);
  725. + raw_spin_unlock(&boot_lock);
  726. }
  727. static const struct of_device_id clk_ids[] = {
  728. @@ -75,7 +75,7 @@
  729. /* make sure write buffer is drained */
  730. mb();
  731. - spin_lock(&boot_lock);
  732. + raw_spin_lock(&boot_lock);
  733. /*
  734. * The secondary processor is waiting to be released from
  735. @@ -107,7 +107,7 @@
  736. * now the secondary core is starting up let it run its
  737. * calibrations, then wait for it to finish
  738. */
  739. - spin_unlock(&boot_lock);
  740. + raw_spin_unlock(&boot_lock);
  741. return pen_release != -1 ? -ENOSYS : 0;
  742. }
  743. diff -Nur linux-4.4.13.orig/arch/arm/mach-qcom/platsmp.c linux-4.4.13/arch/arm/mach-qcom/platsmp.c
  744. --- linux-4.4.13.orig/arch/arm/mach-qcom/platsmp.c 2016-06-08 03:14:51.000000000 +0200
  745. +++ linux-4.4.13/arch/arm/mach-qcom/platsmp.c 2016-06-22 21:55:07.974523867 +0200
  746. @@ -46,7 +46,7 @@
  747. extern void secondary_startup_arm(void);
  748. -static DEFINE_SPINLOCK(boot_lock);
  749. +static DEFINE_RAW_SPINLOCK(boot_lock);
  750. #ifdef CONFIG_HOTPLUG_CPU
  751. static void qcom_cpu_die(unsigned int cpu)
  752. @@ -60,8 +60,8 @@
  753. /*
  754. * Synchronise with the boot thread.
  755. */
  756. - spin_lock(&boot_lock);
  757. - spin_unlock(&boot_lock);
  758. + raw_spin_lock(&boot_lock);
  759. + raw_spin_unlock(&boot_lock);
  760. }
  761. static int scss_release_secondary(unsigned int cpu)
  762. @@ -284,7 +284,7 @@
  763. * set synchronisation state between this boot processor
  764. * and the secondary one
  765. */
  766. - spin_lock(&boot_lock);
  767. + raw_spin_lock(&boot_lock);
  768. /*
  769. * Send the secondary CPU a soft interrupt, thereby causing
  770. @@ -297,7 +297,7 @@
  771. * now the secondary core is starting up let it run its
  772. * calibrations, then wait for it to finish
  773. */
  774. - spin_unlock(&boot_lock);
  775. + raw_spin_unlock(&boot_lock);
  776. return ret;
  777. }
  778. diff -Nur linux-4.4.13.orig/arch/arm/mach-spear/platsmp.c linux-4.4.13/arch/arm/mach-spear/platsmp.c
  779. --- linux-4.4.13.orig/arch/arm/mach-spear/platsmp.c 2016-06-08 03:14:51.000000000 +0200
  780. +++ linux-4.4.13/arch/arm/mach-spear/platsmp.c 2016-06-22 21:55:07.974523867 +0200
  781. @@ -32,7 +32,7 @@
  782. sync_cache_w(&pen_release);
  783. }
  784. -static DEFINE_SPINLOCK(boot_lock);
  785. +static DEFINE_RAW_SPINLOCK(boot_lock);
  786. static void __iomem *scu_base = IOMEM(VA_SCU_BASE);
  787. @@ -47,8 +47,8 @@
  788. /*
  789. * Synchronise with the boot thread.
  790. */
  791. - spin_lock(&boot_lock);
  792. - spin_unlock(&boot_lock);
  793. + raw_spin_lock(&boot_lock);
  794. + raw_spin_unlock(&boot_lock);
  795. }
  796. static int spear13xx_boot_secondary(unsigned int cpu, struct task_struct *idle)
  797. @@ -59,7 +59,7 @@
  798. * set synchronisation state between this boot processor
  799. * and the secondary one
  800. */
  801. - spin_lock(&boot_lock);
  802. + raw_spin_lock(&boot_lock);
  803. /*
  804. * The secondary processor is waiting to be released from
  805. @@ -84,7 +84,7 @@
  806. * now the secondary core is starting up let it run its
  807. * calibrations, then wait for it to finish
  808. */
  809. - spin_unlock(&boot_lock);
  810. + raw_spin_unlock(&boot_lock);
  811. return pen_release != -1 ? -ENOSYS : 0;
  812. }
  813. diff -Nur linux-4.4.13.orig/arch/arm/mach-sti/platsmp.c linux-4.4.13/arch/arm/mach-sti/platsmp.c
  814. --- linux-4.4.13.orig/arch/arm/mach-sti/platsmp.c 2016-06-08 03:14:51.000000000 +0200
  815. +++ linux-4.4.13/arch/arm/mach-sti/platsmp.c 2016-06-22 21:55:07.974523867 +0200
  816. @@ -35,7 +35,7 @@
  817. sync_cache_w(&pen_release);
  818. }
  819. -static DEFINE_SPINLOCK(boot_lock);
  820. +static DEFINE_RAW_SPINLOCK(boot_lock);
  821. static void sti_secondary_init(unsigned int cpu)
  822. {
  823. @@ -48,8 +48,8 @@
  824. /*
  825. * Synchronise with the boot thread.
  826. */
  827. - spin_lock(&boot_lock);
  828. - spin_unlock(&boot_lock);
  829. + raw_spin_lock(&boot_lock);
  830. + raw_spin_unlock(&boot_lock);
  831. }
  832. static int sti_boot_secondary(unsigned int cpu, struct task_struct *idle)
  833. @@ -60,7 +60,7 @@
  834. * set synchronisation state between this boot processor
  835. * and the secondary one
  836. */
  837. - spin_lock(&boot_lock);
  838. + raw_spin_lock(&boot_lock);
  839. /*
  840. * The secondary processor is waiting to be released from
  841. @@ -91,7 +91,7 @@
  842. * now the secondary core is starting up let it run its
  843. * calibrations, then wait for it to finish
  844. */
  845. - spin_unlock(&boot_lock);
  846. + raw_spin_unlock(&boot_lock);
  847. return pen_release != -1 ? -ENOSYS : 0;
  848. }
  849. diff -Nur linux-4.4.13.orig/arch/arm/mm/fault.c linux-4.4.13/arch/arm/mm/fault.c
  850. --- linux-4.4.13.orig/arch/arm/mm/fault.c 2016-06-08 03:14:51.000000000 +0200
  851. +++ linux-4.4.13/arch/arm/mm/fault.c 2016-06-22 21:55:07.974523867 +0200
  852. @@ -430,6 +430,9 @@
  853. if (addr < TASK_SIZE)
  854. return do_page_fault(addr, fsr, regs);
  855. + if (interrupts_enabled(regs))
  856. + local_irq_enable();
  857. +
  858. if (user_mode(regs))
  859. goto bad_area;
  860. @@ -497,6 +500,9 @@
  861. static int
  862. do_sect_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  863. {
  864. + if (interrupts_enabled(regs))
  865. + local_irq_enable();
  866. +
  867. do_bad_area(addr, fsr, regs);
  868. return 0;
  869. }
  870. diff -Nur linux-4.4.13.orig/arch/arm/mm/highmem.c linux-4.4.13/arch/arm/mm/highmem.c
  871. --- linux-4.4.13.orig/arch/arm/mm/highmem.c 2016-06-08 03:14:51.000000000 +0200
  872. +++ linux-4.4.13/arch/arm/mm/highmem.c 2016-06-22 21:55:07.974523867 +0200
  873. @@ -34,6 +34,11 @@
  874. return *ptep;
  875. }
  876. +static unsigned int fixmap_idx(int type)
  877. +{
  878. + return FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
  879. +}
  880. +
  881. void *kmap(struct page *page)
  882. {
  883. might_sleep();
  884. @@ -54,12 +59,13 @@
  885. void *kmap_atomic(struct page *page)
  886. {
  887. + pte_t pte = mk_pte(page, kmap_prot);
  888. unsigned int idx;
  889. unsigned long vaddr;
  890. void *kmap;
  891. int type;
  892. - preempt_disable();
  893. + preempt_disable_nort();
  894. pagefault_disable();
  895. if (!PageHighMem(page))
  896. return page_address(page);
  897. @@ -79,7 +85,7 @@
  898. type = kmap_atomic_idx_push();
  899. - idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
  900. + idx = fixmap_idx(type);
  901. vaddr = __fix_to_virt(idx);
  902. #ifdef CONFIG_DEBUG_HIGHMEM
  903. /*
  904. @@ -93,7 +99,10 @@
  905. * in place, so the contained TLB flush ensures the TLB is updated
  906. * with the new mapping.
  907. */
  908. - set_fixmap_pte(idx, mk_pte(page, kmap_prot));
  909. +#ifdef CONFIG_PREEMPT_RT_FULL
  910. + current->kmap_pte[type] = pte;
  911. +#endif
  912. + set_fixmap_pte(idx, pte);
  913. return (void *)vaddr;
  914. }
  915. @@ -106,44 +115,75 @@
  916. if (kvaddr >= (void *)FIXADDR_START) {
  917. type = kmap_atomic_idx();
  918. - idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
  919. + idx = fixmap_idx(type);
  920. if (cache_is_vivt())
  921. __cpuc_flush_dcache_area((void *)vaddr, PAGE_SIZE);
  922. +#ifdef CONFIG_PREEMPT_RT_FULL
  923. + current->kmap_pte[type] = __pte(0);
  924. +#endif
  925. #ifdef CONFIG_DEBUG_HIGHMEM
  926. BUG_ON(vaddr != __fix_to_virt(idx));
  927. - set_fixmap_pte(idx, __pte(0));
  928. #else
  929. (void) idx; /* to kill a warning */
  930. #endif
  931. + set_fixmap_pte(idx, __pte(0));
  932. kmap_atomic_idx_pop();
  933. } else if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) {
  934. /* this address was obtained through kmap_high_get() */
  935. kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)]));
  936. }
  937. pagefault_enable();
  938. - preempt_enable();
  939. + preempt_enable_nort();
  940. }
  941. EXPORT_SYMBOL(__kunmap_atomic);
  942. void *kmap_atomic_pfn(unsigned long pfn)
  943. {
  944. + pte_t pte = pfn_pte(pfn, kmap_prot);
  945. unsigned long vaddr;
  946. int idx, type;
  947. struct page *page = pfn_to_page(pfn);
  948. - preempt_disable();
  949. + preempt_disable_nort();
  950. pagefault_disable();
  951. if (!PageHighMem(page))
  952. return page_address(page);
  953. type = kmap_atomic_idx_push();
  954. - idx = FIX_KMAP_BEGIN + type + KM_TYPE_NR * smp_processor_id();
  955. + idx = fixmap_idx(type);
  956. vaddr = __fix_to_virt(idx);
  957. #ifdef CONFIG_DEBUG_HIGHMEM
  958. BUG_ON(!pte_none(get_fixmap_pte(vaddr)));
  959. #endif
  960. - set_fixmap_pte(idx, pfn_pte(pfn, kmap_prot));
  961. +#ifdef CONFIG_PREEMPT_RT_FULL
  962. + current->kmap_pte[type] = pte;
  963. +#endif
  964. + set_fixmap_pte(idx, pte);
  965. return (void *)vaddr;
  966. }
  967. +#if defined CONFIG_PREEMPT_RT_FULL
  968. +void switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p)
  969. +{
  970. + int i;
  971. +
  972. + /*
  973. + * Clear @prev's kmap_atomic mappings
  974. + */
  975. + for (i = 0; i < prev_p->kmap_idx; i++) {
  976. + int idx = fixmap_idx(i);
  977. +
  978. + set_fixmap_pte(idx, __pte(0));
  979. + }
  980. + /*
  981. + * Restore @next_p's kmap_atomic mappings
  982. + */
  983. + for (i = 0; i < next_p->kmap_idx; i++) {
  984. + int idx = fixmap_idx(i);
  985. +
  986. + if (!pte_none(next_p->kmap_pte[i]))
  987. + set_fixmap_pte(idx, next_p->kmap_pte[i]);
  988. + }
  989. +}
  990. +#endif
  991. diff -Nur linux-4.4.13.orig/arch/arm/plat-versatile/platsmp.c linux-4.4.13/arch/arm/plat-versatile/platsmp.c
  992. --- linux-4.4.13.orig/arch/arm/plat-versatile/platsmp.c 2016-06-08 03:14:51.000000000 +0200
  993. +++ linux-4.4.13/arch/arm/plat-versatile/platsmp.c 2016-06-22 21:55:07.974523867 +0200
  994. @@ -30,7 +30,7 @@
  995. sync_cache_w(&pen_release);
  996. }
  997. -static DEFINE_SPINLOCK(boot_lock);
  998. +static DEFINE_RAW_SPINLOCK(boot_lock);
  999. void versatile_secondary_init(unsigned int cpu)
  1000. {
  1001. @@ -43,8 +43,8 @@
  1002. /*
  1003. * Synchronise with the boot thread.
  1004. */
  1005. - spin_lock(&boot_lock);
  1006. - spin_unlock(&boot_lock);
  1007. + raw_spin_lock(&boot_lock);
  1008. + raw_spin_unlock(&boot_lock);
  1009. }
  1010. int versatile_boot_secondary(unsigned int cpu, struct task_struct *idle)
  1011. @@ -55,7 +55,7 @@
  1012. * Set synchronisation state between this boot processor
  1013. * and the secondary one
  1014. */
  1015. - spin_lock(&boot_lock);
  1016. + raw_spin_lock(&boot_lock);
  1017. /*
  1018. * This is really belt and braces; we hold unintended secondary
  1019. @@ -85,7 +85,7 @@
  1020. * now the secondary core is starting up let it run its
  1021. * calibrations, then wait for it to finish
  1022. */
  1023. - spin_unlock(&boot_lock);
  1024. + raw_spin_unlock(&boot_lock);
  1025. return pen_release != -1 ? -ENOSYS : 0;
  1026. }
  1027. diff -Nur linux-4.4.13.orig/arch/arm64/include/asm/thread_info.h linux-4.4.13/arch/arm64/include/asm/thread_info.h
  1028. --- linux-4.4.13.orig/arch/arm64/include/asm/thread_info.h 2016-06-08 03:14:51.000000000 +0200
  1029. +++ linux-4.4.13/arch/arm64/include/asm/thread_info.h 2016-06-22 21:55:07.974523867 +0200
  1030. @@ -49,6 +49,7 @@
  1031. mm_segment_t addr_limit; /* address limit */
  1032. struct task_struct *task; /* main task structure */
  1033. int preempt_count; /* 0 => preemptable, <0 => bug */
  1034. + int preempt_lazy_count; /* 0 => preemptable, <0 => bug */
  1035. int cpu; /* cpu */
  1036. };
  1037. @@ -103,6 +104,7 @@
  1038. #define TIF_NEED_RESCHED 1
  1039. #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
  1040. #define TIF_FOREIGN_FPSTATE 3 /* CPU's FP state is not current's */
  1041. +#define TIF_NEED_RESCHED_LAZY 4
  1042. #define TIF_NOHZ 7
  1043. #define TIF_SYSCALL_TRACE 8
  1044. #define TIF_SYSCALL_AUDIT 9
  1045. @@ -118,6 +120,7 @@
  1046. #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  1047. #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
  1048. #define _TIF_FOREIGN_FPSTATE (1 << TIF_FOREIGN_FPSTATE)
  1049. +#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)
  1050. #define _TIF_NOHZ (1 << TIF_NOHZ)
  1051. #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  1052. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  1053. @@ -126,7 +129,8 @@
  1054. #define _TIF_32BIT (1 << TIF_32BIT)
  1055. #define _TIF_WORK_MASK (_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
  1056. - _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE)
  1057. + _TIF_NOTIFY_RESUME | _TIF_FOREIGN_FPSTATE | \
  1058. + _TIF_NEED_RESCHED_LAZY)
  1059. #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
  1060. _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
  1061. diff -Nur linux-4.4.13.orig/arch/arm64/Kconfig linux-4.4.13/arch/arm64/Kconfig
  1062. --- linux-4.4.13.orig/arch/arm64/Kconfig 2016-06-08 03:14:51.000000000 +0200
  1063. +++ linux-4.4.13/arch/arm64/Kconfig 2016-06-22 21:55:07.974523867 +0200
  1064. @@ -76,6 +76,7 @@
  1065. select HAVE_PERF_REGS
  1066. select HAVE_PERF_USER_STACK_DUMP
  1067. select HAVE_RCU_TABLE_FREE
  1068. + select HAVE_PREEMPT_LAZY
  1069. select HAVE_SYSCALL_TRACEPOINTS
  1070. select IOMMU_DMA if IOMMU_SUPPORT
  1071. select IRQ_DOMAIN
  1072. @@ -562,7 +563,7 @@
  1073. config XEN
  1074. bool "Xen guest support on ARM64"
  1075. - depends on ARM64 && OF
  1076. + depends on ARM64 && OF && !PREEMPT_RT_FULL
  1077. select SWIOTLB_XEN
  1078. help
  1079. Say Y if you want to run Linux in a Virtual Machine on Xen on ARM64.
  1080. diff -Nur linux-4.4.13.orig/arch/arm64/kernel/asm-offsets.c linux-4.4.13/arch/arm64/kernel/asm-offsets.c
  1081. --- linux-4.4.13.orig/arch/arm64/kernel/asm-offsets.c 2016-06-08 03:14:51.000000000 +0200
  1082. +++ linux-4.4.13/arch/arm64/kernel/asm-offsets.c 2016-06-22 21:55:07.974523867 +0200
  1083. @@ -35,6 +35,7 @@
  1084. BLANK();
  1085. DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
  1086. DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
  1087. + DEFINE(TI_PREEMPT_LAZY, offsetof(struct thread_info, preempt_lazy_count));
  1088. DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit));
  1089. DEFINE(TI_TASK, offsetof(struct thread_info, task));
  1090. DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  1091. diff -Nur linux-4.4.13.orig/arch/arm64/kernel/entry.S linux-4.4.13/arch/arm64/kernel/entry.S
  1092. --- linux-4.4.13.orig/arch/arm64/kernel/entry.S 2016-06-08 03:14:51.000000000 +0200
  1093. +++ linux-4.4.13/arch/arm64/kernel/entry.S 2016-06-22 21:55:07.978523867 +0200
  1094. @@ -363,11 +363,16 @@
  1095. #ifdef CONFIG_PREEMPT
  1096. get_thread_info tsk
  1097. ldr w24, [tsk, #TI_PREEMPT] // get preempt count
  1098. - cbnz w24, 1f // preempt count != 0
  1099. + cbnz w24, 2f // preempt count != 0
  1100. ldr x0, [tsk, #TI_FLAGS] // get flags
  1101. - tbz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling?
  1102. - bl el1_preempt
  1103. + tbnz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling?
  1104. +
  1105. + ldr w24, [tsk, #TI_PREEMPT_LAZY] // get preempt lazy count
  1106. + cbnz w24, 2f // preempt lazy count != 0
  1107. + tbz x0, #TIF_NEED_RESCHED_LAZY, 2f // needs rescheduling?
  1108. 1:
  1109. + bl el1_preempt
  1110. +2:
  1111. #endif
  1112. #ifdef CONFIG_TRACE_IRQFLAGS
  1113. bl trace_hardirqs_on
  1114. @@ -381,6 +386,7 @@
  1115. 1: bl preempt_schedule_irq // irq en/disable is done inside
  1116. ldr x0, [tsk, #TI_FLAGS] // get new tasks TI_FLAGS
  1117. tbnz x0, #TIF_NEED_RESCHED, 1b // needs rescheduling?
  1118. + tbnz x0, #TIF_NEED_RESCHED_LAZY, 1b // needs rescheduling?
  1119. ret x24
  1120. #endif
  1121. @@ -625,6 +631,7 @@
  1122. */
  1123. work_pending:
  1124. tbnz x1, #TIF_NEED_RESCHED, work_resched
  1125. + tbnz x1, #TIF_NEED_RESCHED_LAZY, work_resched
  1126. /* TIF_SIGPENDING, TIF_NOTIFY_RESUME or TIF_FOREIGN_FPSTATE case */
  1127. ldr x2, [sp, #S_PSTATE]
  1128. mov x0, sp // 'regs'
  1129. diff -Nur linux-4.4.13.orig/arch/Kconfig linux-4.4.13/arch/Kconfig
  1130. --- linux-4.4.13.orig/arch/Kconfig 2016-06-08 03:14:51.000000000 +0200
  1131. +++ linux-4.4.13/arch/Kconfig 2016-06-22 21:55:07.978523867 +0200
  1132. @@ -9,6 +9,7 @@
  1133. tristate "OProfile system profiling"
  1134. depends on PROFILING
  1135. depends on HAVE_OPROFILE
  1136. + depends on !PREEMPT_RT_FULL
  1137. select RING_BUFFER
  1138. select RING_BUFFER_ALLOW_SWAP
  1139. help
  1140. @@ -52,6 +53,7 @@
  1141. config JUMP_LABEL
  1142. bool "Optimize very unlikely/likely branches"
  1143. depends on HAVE_ARCH_JUMP_LABEL
  1144. + depends on (!INTERRUPT_OFF_HIST && !PREEMPT_OFF_HIST && !WAKEUP_LATENCY_HIST && !MISSED_TIMER_OFFSETS_HIST)
  1145. help
  1146. This option enables a transparent branch optimization that
  1147. makes certain almost-always-true or almost-always-false branch
  1148. diff -Nur linux-4.4.13.orig/arch/mips/Kconfig linux-4.4.13/arch/mips/Kconfig
  1149. --- linux-4.4.13.orig/arch/mips/Kconfig 2016-06-08 03:14:51.000000000 +0200
  1150. +++ linux-4.4.13/arch/mips/Kconfig 2016-06-22 21:55:07.978523867 +0200
  1151. @@ -2410,7 +2410,7 @@
  1152. #
  1153. config HIGHMEM
  1154. bool "High Memory Support"
  1155. - depends on 32BIT && CPU_SUPPORTS_HIGHMEM && SYS_SUPPORTS_HIGHMEM && !CPU_MIPS32_3_5_EVA
  1156. + depends on 32BIT && CPU_SUPPORTS_HIGHMEM && SYS_SUPPORTS_HIGHMEM && !CPU_MIPS32_3_5_EVA && !PREEMPT_RT_FULL
  1157. config CPU_SUPPORTS_HIGHMEM
  1158. bool
  1159. diff -Nur linux-4.4.13.orig/arch/mips/kvm/mips.c linux-4.4.13/arch/mips/kvm/mips.c
  1160. --- linux-4.4.13.orig/arch/mips/kvm/mips.c 2016-06-08 03:14:51.000000000 +0200
  1161. +++ linux-4.4.13/arch/mips/kvm/mips.c 2016-06-22 21:55:07.978523867 +0200
  1162. @@ -445,8 +445,8 @@
  1163. dvcpu->arch.wait = 0;
  1164. - if (waitqueue_active(&dvcpu->wq))
  1165. - wake_up_interruptible(&dvcpu->wq);
  1166. + if (swait_active(&dvcpu->wq))
  1167. + swake_up(&dvcpu->wq);
  1168. return 0;
  1169. }
  1170. @@ -1174,8 +1174,8 @@
  1171. kvm_mips_callbacks->queue_timer_int(vcpu);
  1172. vcpu->arch.wait = 0;
  1173. - if (waitqueue_active(&vcpu->wq))
  1174. - wake_up_interruptible(&vcpu->wq);
  1175. + if (swait_active(&vcpu->wq))
  1176. + swake_up(&vcpu->wq);
  1177. }
  1178. /* low level hrtimer wake routine */
  1179. diff -Nur linux-4.4.13.orig/arch/powerpc/include/asm/kvm_host.h linux-4.4.13/arch/powerpc/include/asm/kvm_host.h
  1180. --- linux-4.4.13.orig/arch/powerpc/include/asm/kvm_host.h 2016-06-08 03:14:51.000000000 +0200
  1181. +++ linux-4.4.13/arch/powerpc/include/asm/kvm_host.h 2016-06-22 21:55:07.978523867 +0200
  1182. @@ -286,7 +286,7 @@
  1183. struct list_head runnable_threads;
  1184. struct list_head preempt_list;
  1185. spinlock_t lock;
  1186. - wait_queue_head_t wq;
  1187. + struct swait_queue_head wq;
  1188. spinlock_t stoltb_lock; /* protects stolen_tb and preempt_tb */
  1189. u64 stolen_tb;
  1190. u64 preempt_tb;
  1191. @@ -626,7 +626,7 @@
  1192. u8 prodded;
  1193. u32 last_inst;
  1194. - wait_queue_head_t *wqp;
  1195. + struct swait_queue_head *wqp;
  1196. struct kvmppc_vcore *vcore;
  1197. int ret;
  1198. int trap;
  1199. diff -Nur linux-4.4.13.orig/arch/powerpc/include/asm/thread_info.h linux-4.4.13/arch/powerpc/include/asm/thread_info.h
  1200. --- linux-4.4.13.orig/arch/powerpc/include/asm/thread_info.h 2016-06-08 03:14:51.000000000 +0200
  1201. +++ linux-4.4.13/arch/powerpc/include/asm/thread_info.h 2016-06-22 21:55:07.978523867 +0200
  1202. @@ -42,6 +42,8 @@
  1203. int cpu; /* cpu we're on */
  1204. int preempt_count; /* 0 => preemptable,
  1205. <0 => BUG */
  1206. + int preempt_lazy_count; /* 0 => preemptable,
  1207. + <0 => BUG */
  1208. unsigned long local_flags; /* private flags for thread */
  1209. /* low level flags - has atomic operations done on it */
  1210. @@ -82,8 +84,7 @@
  1211. #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  1212. #define TIF_SIGPENDING 1 /* signal pending */
  1213. #define TIF_NEED_RESCHED 2 /* rescheduling necessary */
  1214. -#define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
  1215. - TIF_NEED_RESCHED */
  1216. +#define TIF_NEED_RESCHED_LAZY 3 /* lazy rescheduling necessary */
  1217. #define TIF_32BIT 4 /* 32 bit binary */
  1218. #define TIF_RESTORE_TM 5 /* need to restore TM FP/VEC/VSX */
  1219. #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
  1220. @@ -101,6 +102,8 @@
  1221. #if defined(CONFIG_PPC64)
  1222. #define TIF_ELF2ABI 18 /* function descriptors must die! */
  1223. #endif
  1224. +#define TIF_POLLING_NRFLAG 19 /* true if poll_idle() is polling
  1225. + TIF_NEED_RESCHED */
  1226. /* as above, but as bit values */
  1227. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  1228. @@ -119,14 +122,16 @@
  1229. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  1230. #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
  1231. #define _TIF_NOHZ (1<<TIF_NOHZ)
  1232. +#define _TIF_NEED_RESCHED_LAZY (1<<TIF_NEED_RESCHED_LAZY)
  1233. #define _TIF_SYSCALL_DOTRACE (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
  1234. _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
  1235. _TIF_NOHZ)
  1236. #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
  1237. _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
  1238. - _TIF_RESTORE_TM)
  1239. + _TIF_RESTORE_TM | _TIF_NEED_RESCHED_LAZY)
  1240. #define _TIF_PERSYSCALL_MASK (_TIF_RESTOREALL|_TIF_NOERROR)
  1241. +#define _TIF_NEED_RESCHED_MASK (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)
  1242. /* Bits in local_flags */
  1243. /* Don't move TLF_NAPPING without adjusting the code in entry_32.S */
  1244. diff -Nur linux-4.4.13.orig/arch/powerpc/Kconfig linux-4.4.13/arch/powerpc/Kconfig
  1245. --- linux-4.4.13.orig/arch/powerpc/Kconfig 2016-06-08 03:14:51.000000000 +0200
  1246. +++ linux-4.4.13/arch/powerpc/Kconfig 2016-06-22 21:55:07.978523867 +0200
  1247. @@ -60,10 +60,11 @@
  1248. config RWSEM_GENERIC_SPINLOCK
  1249. bool
  1250. + default y if PREEMPT_RT_FULL
  1251. config RWSEM_XCHGADD_ALGORITHM
  1252. bool
  1253. - default y
  1254. + default y if !PREEMPT_RT_FULL
  1255. config GENERIC_LOCKBREAK
  1256. bool
  1257. @@ -141,6 +142,7 @@
  1258. select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
  1259. select GENERIC_STRNCPY_FROM_USER
  1260. select GENERIC_STRNLEN_USER
  1261. + select HAVE_PREEMPT_LAZY
  1262. select HAVE_MOD_ARCH_SPECIFIC
  1263. select MODULES_USE_ELF_RELA
  1264. select CLONE_BACKWARDS
  1265. @@ -319,7 +321,7 @@
  1266. config HIGHMEM
  1267. bool "High memory support"
  1268. - depends on PPC32
  1269. + depends on PPC32 && !PREEMPT_RT_FULL
  1270. source kernel/Kconfig.hz
  1271. source kernel/Kconfig.preempt
  1272. diff -Nur linux-4.4.13.orig/arch/powerpc/kernel/asm-offsets.c linux-4.4.13/arch/powerpc/kernel/asm-offsets.c
  1273. --- linux-4.4.13.orig/arch/powerpc/kernel/asm-offsets.c 2016-06-08 03:14:51.000000000 +0200
  1274. +++ linux-4.4.13/arch/powerpc/kernel/asm-offsets.c 2016-06-22 21:55:07.978523867 +0200
  1275. @@ -160,6 +160,7 @@
  1276. DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
  1277. DEFINE(TI_LOCAL_FLAGS, offsetof(struct thread_info, local_flags));
  1278. DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
  1279. + DEFINE(TI_PREEMPT_LAZY, offsetof(struct thread_info, preempt_lazy_count));
  1280. DEFINE(TI_TASK, offsetof(struct thread_info, task));
  1281. DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  1282. diff -Nur linux-4.4.13.orig/arch/powerpc/kernel/entry_32.S linux-4.4.13/arch/powerpc/kernel/entry_32.S
  1283. --- linux-4.4.13.orig/arch/powerpc/kernel/entry_32.S 2016-06-08 03:14:51.000000000 +0200
  1284. +++ linux-4.4.13/arch/powerpc/kernel/entry_32.S 2016-06-22 21:55:07.978523867 +0200
  1285. @@ -818,7 +818,14 @@
  1286. cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
  1287. bne restore
  1288. andi. r8,r8,_TIF_NEED_RESCHED
  1289. + bne+ 1f
  1290. + lwz r0,TI_PREEMPT_LAZY(r9)
  1291. + cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
  1292. + bne restore
  1293. + lwz r0,TI_FLAGS(r9)
  1294. + andi. r0,r0,_TIF_NEED_RESCHED_LAZY
  1295. beq+ restore
  1296. +1:
  1297. lwz r3,_MSR(r1)
  1298. andi. r0,r3,MSR_EE /* interrupts off? */
  1299. beq restore /* don't schedule if so */
  1300. @@ -829,11 +836,11 @@
  1301. */
  1302. bl trace_hardirqs_off
  1303. #endif
  1304. -1: bl preempt_schedule_irq
  1305. +2: bl preempt_schedule_irq
  1306. CURRENT_THREAD_INFO(r9, r1)
  1307. lwz r3,TI_FLAGS(r9)
  1308. - andi. r0,r3,_TIF_NEED_RESCHED
  1309. - bne- 1b
  1310. + andi. r0,r3,_TIF_NEED_RESCHED_MASK
  1311. + bne- 2b
  1312. #ifdef CONFIG_TRACE_IRQFLAGS
  1313. /* And now, to properly rebalance the above, we tell lockdep they
  1314. * are being turned back on, which will happen when we return
  1315. @@ -1154,7 +1161,7 @@
  1316. #endif /* !(CONFIG_4xx || CONFIG_BOOKE) */
  1317. do_work: /* r10 contains MSR_KERNEL here */
  1318. - andi. r0,r9,_TIF_NEED_RESCHED
  1319. + andi. r0,r9,_TIF_NEED_RESCHED_MASK
  1320. beq do_user_signal
  1321. do_resched: /* r10 contains MSR_KERNEL here */
  1322. @@ -1175,7 +1182,7 @@
  1323. MTMSRD(r10) /* disable interrupts */
  1324. CURRENT_THREAD_INFO(r9, r1)
  1325. lwz r9,TI_FLAGS(r9)
  1326. - andi. r0,r9,_TIF_NEED_RESCHED
  1327. + andi. r0,r9,_TIF_NEED_RESCHED_MASK
  1328. bne- do_resched
  1329. andi. r0,r9,_TIF_USER_WORK_MASK
  1330. beq restore_user
  1331. diff -Nur linux-4.4.13.orig/arch/powerpc/kernel/entry_64.S linux-4.4.13/arch/powerpc/kernel/entry_64.S
  1332. --- linux-4.4.13.orig/arch/powerpc/kernel/entry_64.S 2016-06-08 03:14:51.000000000 +0200
  1333. +++ linux-4.4.13/arch/powerpc/kernel/entry_64.S 2016-06-22 21:55:07.978523867 +0200
  1334. @@ -683,7 +683,7 @@
  1335. #else
  1336. beq restore
  1337. #endif
  1338. -1: andi. r0,r4,_TIF_NEED_RESCHED
  1339. +1: andi. r0,r4,_TIF_NEED_RESCHED_MASK
  1340. beq 2f
  1341. bl restore_interrupts
  1342. SCHEDULE_USER
  1343. @@ -745,10 +745,18 @@
  1344. #ifdef CONFIG_PREEMPT
  1345. /* Check if we need to preempt */
  1346. + lwz r8,TI_PREEMPT(r9)
  1347. + cmpwi 0,r8,0 /* if non-zero, just restore regs and return */
  1348. + bne restore
  1349. andi. r0,r4,_TIF_NEED_RESCHED
  1350. + bne+ check_count
  1351. +
  1352. + andi. r0,r4,_TIF_NEED_RESCHED_LAZY
  1353. beq+ restore
  1354. + lwz r8,TI_PREEMPT_LAZY(r9)
  1355. +
  1356. /* Check that preempt_count() == 0 and interrupts are enabled */
  1357. - lwz r8,TI_PREEMPT(r9)
  1358. +check_count:
  1359. cmpwi cr1,r8,0
  1360. ld r0,SOFTE(r1)
  1361. cmpdi r0,0
  1362. @@ -765,7 +773,7 @@
  1363. /* Re-test flags and eventually loop */
  1364. CURRENT_THREAD_INFO(r9, r1)
  1365. ld r4,TI_FLAGS(r9)
  1366. - andi. r0,r4,_TIF_NEED_RESCHED
  1367. + andi. r0,r4,_TIF_NEED_RESCHED_MASK
  1368. bne 1b
  1369. /*
  1370. diff -Nur linux-4.4.13.orig/arch/powerpc/kernel/irq.c linux-4.4.13/arch/powerpc/kernel/irq.c
  1371. --- linux-4.4.13.orig/arch/powerpc/kernel/irq.c 2016-06-08 03:14:51.000000000 +0200
  1372. +++ linux-4.4.13/arch/powerpc/kernel/irq.c 2016-06-22 21:55:07.978523867 +0200
  1373. @@ -614,6 +614,7 @@
  1374. }
  1375. }
  1376. +#ifndef CONFIG_PREEMPT_RT_FULL
  1377. void do_softirq_own_stack(void)
  1378. {
  1379. struct thread_info *curtp, *irqtp;
  1380. @@ -631,6 +632,7 @@
  1381. if (irqtp->flags)
  1382. set_bits(irqtp->flags, &curtp->flags);
  1383. }
  1384. +#endif
  1385. irq_hw_number_t virq_to_hw(unsigned int virq)
  1386. {
  1387. diff -Nur linux-4.4.13.orig/arch/powerpc/kernel/misc_32.S linux-4.4.13/arch/powerpc/kernel/misc_32.S
  1388. --- linux-4.4.13.orig/arch/powerpc/kernel/misc_32.S 2016-06-08 03:14:51.000000000 +0200
  1389. +++ linux-4.4.13/arch/powerpc/kernel/misc_32.S 2016-06-22 21:55:07.978523867 +0200
  1390. @@ -40,6 +40,7 @@
  1391. * We store the saved ksp_limit in the unused part
  1392. * of the STACK_FRAME_OVERHEAD
  1393. */
  1394. +#ifndef CONFIG_PREEMPT_RT_FULL
  1395. _GLOBAL(call_do_softirq)
  1396. mflr r0
  1397. stw r0,4(r1)
  1398. @@ -56,6 +57,7 @@
  1399. stw r10,THREAD+KSP_LIMIT(r2)
  1400. mtlr r0
  1401. blr
  1402. +#endif
  1403. /*
  1404. * void call_do_irq(struct pt_regs *regs, struct thread_info *irqtp);
  1405. diff -Nur linux-4.4.13.orig/arch/powerpc/kernel/misc_64.S linux-4.4.13/arch/powerpc/kernel/misc_64.S
  1406. --- linux-4.4.13.orig/arch/powerpc/kernel/misc_64.S 2016-06-08 03:14:51.000000000 +0200
  1407. +++ linux-4.4.13/arch/powerpc/kernel/misc_64.S 2016-06-22 21:55:07.978523867 +0200
  1408. @@ -30,6 +30,7 @@
  1409. .text
  1410. +#ifndef CONFIG_PREEMPT_RT_FULL
  1411. _GLOBAL(call_do_softirq)
  1412. mflr r0
  1413. std r0,16(r1)
  1414. @@ -40,6 +41,7 @@
  1415. ld r0,16(r1)
  1416. mtlr r0
  1417. blr
  1418. +#endif
  1419. _GLOBAL(call_do_irq)
  1420. mflr r0
  1421. diff -Nur linux-4.4.13.orig/arch/powerpc/kvm/book3s_hv.c linux-4.4.13/arch/powerpc/kvm/book3s_hv.c
  1422. --- linux-4.4.13.orig/arch/powerpc/kvm/book3s_hv.c 2016-06-08 03:14:51.000000000 +0200
  1423. +++ linux-4.4.13/arch/powerpc/kvm/book3s_hv.c 2016-06-22 21:55:07.978523867 +0200
  1424. @@ -114,11 +114,11 @@
  1425. static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu)
  1426. {
  1427. int cpu;
  1428. - wait_queue_head_t *wqp;
  1429. + struct swait_queue_head *wqp;
  1430. wqp = kvm_arch_vcpu_wq(vcpu);
  1431. - if (waitqueue_active(wqp)) {
  1432. - wake_up_interruptible(wqp);
  1433. + if (swait_active(wqp)) {
  1434. + swake_up(wqp);
  1435. ++vcpu->stat.halt_wakeup;
  1436. }
  1437. @@ -707,8 +707,8 @@
  1438. tvcpu->arch.prodded = 1;
  1439. smp_mb();
  1440. if (vcpu->arch.ceded) {
  1441. - if (waitqueue_active(&vcpu->wq)) {
  1442. - wake_up_interruptible(&vcpu->wq);
  1443. + if (swait_active(&vcpu->wq)) {
  1444. + swake_up(&vcpu->wq);
  1445. vcpu->stat.halt_wakeup++;
  1446. }
  1447. }
  1448. @@ -1447,7 +1447,7 @@
  1449. INIT_LIST_HEAD(&vcore->runnable_threads);
  1450. spin_lock_init(&vcore->lock);
  1451. spin_lock_init(&vcore->stoltb_lock);
  1452. - init_waitqueue_head(&vcore->wq);
  1453. + init_swait_queue_head(&vcore->wq);
  1454. vcore->preempt_tb = TB_NIL;
  1455. vcore->lpcr = kvm->arch.lpcr;
  1456. vcore->first_vcpuid = core * threads_per_subcore;
  1457. @@ -2519,10 +2519,9 @@
  1458. {
  1459. struct kvm_vcpu *vcpu;
  1460. int do_sleep = 1;
  1461. + DECLARE_SWAITQUEUE(wait);
  1462. - DEFINE_WAIT(wait);
  1463. -
  1464. - prepare_to_wait(&vc->wq, &wait, TASK_INTERRUPTIBLE);
  1465. + prepare_to_swait(&vc->wq, &wait, TASK_INTERRUPTIBLE);
  1466. /*
  1467. * Check one last time for pending exceptions and ceded state after
  1468. @@ -2536,7 +2535,7 @@
  1469. }
  1470. if (!do_sleep) {
  1471. - finish_wait(&vc->wq, &wait);
  1472. + finish_swait(&vc->wq, &wait);
  1473. return;
  1474. }
  1475. @@ -2544,7 +2543,7 @@
  1476. trace_kvmppc_vcore_blocked(vc, 0);
  1477. spin_unlock(&vc->lock);
  1478. schedule();
  1479. - finish_wait(&vc->wq, &wait);
  1480. + finish_swait(&vc->wq, &wait);
  1481. spin_lock(&vc->lock);
  1482. vc->vcore_state = VCORE_INACTIVE;
  1483. trace_kvmppc_vcore_blocked(vc, 1);
  1484. @@ -2600,7 +2599,7 @@
  1485. kvmppc_start_thread(vcpu, vc);
  1486. trace_kvm_guest_enter(vcpu);
  1487. } else if (vc->vcore_state == VCORE_SLEEPING) {
  1488. - wake_up(&vc->wq);
  1489. + swake_up(&vc->wq);
  1490. }
  1491. }
  1492. diff -Nur linux-4.4.13.orig/arch/powerpc/kvm/Kconfig linux-4.4.13/arch/powerpc/kvm/Kconfig
  1493. --- linux-4.4.13.orig/arch/powerpc/kvm/Kconfig 2016-06-08 03:14:51.000000000 +0200
  1494. +++ linux-4.4.13/arch/powerpc/kvm/Kconfig 2016-06-22 21:55:07.978523867 +0200
  1495. @@ -172,6 +172,7 @@
  1496. config KVM_MPIC
  1497. bool "KVM in-kernel MPIC emulation"
  1498. depends on KVM && E500
  1499. + depends on !PREEMPT_RT_FULL
  1500. select HAVE_KVM_IRQCHIP
  1501. select HAVE_KVM_IRQFD
  1502. select HAVE_KVM_IRQ_ROUTING
  1503. diff -Nur linux-4.4.13.orig/arch/powerpc/platforms/ps3/device-init.c linux-4.4.13/arch/powerpc/platforms/ps3/device-init.c
  1504. --- linux-4.4.13.orig/arch/powerpc/platforms/ps3/device-init.c 2016-06-08 03:14:51.000000000 +0200
  1505. +++ linux-4.4.13/arch/powerpc/platforms/ps3/device-init.c 2016-06-22 21:55:07.982523867 +0200
  1506. @@ -752,7 +752,7 @@
  1507. }
  1508. pr_debug("%s:%u: notification %s issued\n", __func__, __LINE__, op);
  1509. - res = wait_event_interruptible(dev->done.wait,
  1510. + res = swait_event_interruptible(dev->done.wait,
  1511. dev->done.done || kthread_should_stop());
  1512. if (kthread_should_stop())
  1513. res = -EINTR;
  1514. diff -Nur linux-4.4.13.orig/arch/s390/include/asm/kvm_host.h linux-4.4.13/arch/s390/include/asm/kvm_host.h
  1515. --- linux-4.4.13.orig/arch/s390/include/asm/kvm_host.h 2016-06-08 03:14:51.000000000 +0200
  1516. +++ linux-4.4.13/arch/s390/include/asm/kvm_host.h 2016-06-22 21:55:07.982523867 +0200
  1517. @@ -427,7 +427,7 @@
  1518. struct kvm_s390_local_interrupt {
  1519. spinlock_t lock;
  1520. struct kvm_s390_float_interrupt *float_int;
  1521. - wait_queue_head_t *wq;
  1522. + struct swait_queue_head *wq;
  1523. atomic_t *cpuflags;
  1524. DECLARE_BITMAP(sigp_emerg_pending, KVM_MAX_VCPUS);
  1525. struct kvm_s390_irq_payload irq;
  1526. diff -Nur linux-4.4.13.orig/arch/s390/kvm/interrupt.c linux-4.4.13/arch/s390/kvm/interrupt.c
  1527. --- linux-4.4.13.orig/arch/s390/kvm/interrupt.c 2016-06-08 03:14:51.000000000 +0200
  1528. +++ linux-4.4.13/arch/s390/kvm/interrupt.c 2016-06-22 21:55:07.982523867 +0200
  1529. @@ -868,13 +868,13 @@
  1530. void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu)
  1531. {
  1532. - if (waitqueue_active(&vcpu->wq)) {
  1533. + if (swait_active(&vcpu->wq)) {
  1534. /*
  1535. * The vcpu gave up the cpu voluntarily, mark it as a good
  1536. * yield-candidate.
  1537. */
  1538. vcpu->preempted = true;
  1539. - wake_up_interruptible(&vcpu->wq);
  1540. + swake_up(&vcpu->wq);
  1541. vcpu->stat.halt_wakeup++;
  1542. }
  1543. }
  1544. diff -Nur linux-4.4.13.orig/arch/sh/kernel/irq.c linux-4.4.13/arch/sh/kernel/irq.c
  1545. --- linux-4.4.13.orig/arch/sh/kernel/irq.c 2016-06-08 03:14:51.000000000 +0200
  1546. +++ linux-4.4.13/arch/sh/kernel/irq.c 2016-06-22 21:55:07.982523867 +0200
  1547. @@ -147,6 +147,7 @@
  1548. hardirq_ctx[cpu] = NULL;
  1549. }
  1550. +#ifndef CONFIG_PREEMPT_RT_FULL
  1551. void do_softirq_own_stack(void)
  1552. {
  1553. struct thread_info *curctx;
  1554. @@ -174,6 +175,7 @@
  1555. "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
  1556. );
  1557. }
  1558. +#endif
  1559. #else
  1560. static inline void handle_one_irq(unsigned int irq)
  1561. {
  1562. diff -Nur linux-4.4.13.orig/arch/sparc/Kconfig linux-4.4.13/arch/sparc/Kconfig
  1563. --- linux-4.4.13.orig/arch/sparc/Kconfig 2016-06-08 03:14:51.000000000 +0200
  1564. +++ linux-4.4.13/arch/sparc/Kconfig 2016-06-22 21:55:07.982523867 +0200
  1565. @@ -189,12 +189,10 @@
  1566. source kernel/Kconfig.hz
  1567. config RWSEM_GENERIC_SPINLOCK
  1568. - bool
  1569. - default y if SPARC32
  1570. + def_bool PREEMPT_RT_FULL
  1571. config RWSEM_XCHGADD_ALGORITHM
  1572. - bool
  1573. - default y if SPARC64
  1574. + def_bool !RWSEM_GENERIC_SPINLOCK && !PREEMPT_RT_FULL
  1575. config GENERIC_HWEIGHT
  1576. bool
  1577. diff -Nur linux-4.4.13.orig/arch/sparc/kernel/irq_64.c linux-4.4.13/arch/sparc/kernel/irq_64.c
  1578. --- linux-4.4.13.orig/arch/sparc/kernel/irq_64.c 2016-06-08 03:14:51.000000000 +0200
  1579. +++ linux-4.4.13/arch/sparc/kernel/irq_64.c 2016-06-22 21:55:07.982523867 +0200
  1580. @@ -854,6 +854,7 @@
  1581. set_irq_regs(old_regs);
  1582. }
  1583. +#ifndef CONFIG_PREEMPT_RT_FULL
  1584. void do_softirq_own_stack(void)
  1585. {
  1586. void *orig_sp, *sp = softirq_stack[smp_processor_id()];
  1587. @@ -868,6 +869,7 @@
  1588. __asm__ __volatile__("mov %0, %%sp"
  1589. : : "r" (orig_sp));
  1590. }
  1591. +#endif
  1592. #ifdef CONFIG_HOTPLUG_CPU
  1593. void fixup_irqs(void)
  1594. diff -Nur linux-4.4.13.orig/arch/x86/crypto/aesni-intel_glue.c linux-4.4.13/arch/x86/crypto/aesni-intel_glue.c
  1595. --- linux-4.4.13.orig/arch/x86/crypto/aesni-intel_glue.c 2016-06-08 03:14:51.000000000 +0200
  1596. +++ linux-4.4.13/arch/x86/crypto/aesni-intel_glue.c 2016-06-22 21:55:07.982523867 +0200
  1597. @@ -383,14 +383,14 @@
  1598. err = blkcipher_walk_virt(desc, &walk);
  1599. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1600. - kernel_fpu_begin();
  1601. while ((nbytes = walk.nbytes)) {
  1602. + kernel_fpu_begin();
  1603. aesni_ecb_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  1604. - nbytes & AES_BLOCK_MASK);
  1605. + nbytes & AES_BLOCK_MASK);
  1606. + kernel_fpu_end();
  1607. nbytes &= AES_BLOCK_SIZE - 1;
  1608. err = blkcipher_walk_done(desc, &walk, nbytes);
  1609. }
  1610. - kernel_fpu_end();
  1611. return err;
  1612. }
  1613. @@ -407,14 +407,14 @@
  1614. err = blkcipher_walk_virt(desc, &walk);
  1615. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1616. - kernel_fpu_begin();
  1617. while ((nbytes = walk.nbytes)) {
  1618. + kernel_fpu_begin();
  1619. aesni_ecb_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  1620. nbytes & AES_BLOCK_MASK);
  1621. + kernel_fpu_end();
  1622. nbytes &= AES_BLOCK_SIZE - 1;
  1623. err = blkcipher_walk_done(desc, &walk, nbytes);
  1624. }
  1625. - kernel_fpu_end();
  1626. return err;
  1627. }
  1628. @@ -431,14 +431,14 @@
  1629. err = blkcipher_walk_virt(desc, &walk);
  1630. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1631. - kernel_fpu_begin();
  1632. while ((nbytes = walk.nbytes)) {
  1633. + kernel_fpu_begin();
  1634. aesni_cbc_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  1635. nbytes & AES_BLOCK_MASK, walk.iv);
  1636. + kernel_fpu_end();
  1637. nbytes &= AES_BLOCK_SIZE - 1;
  1638. err = blkcipher_walk_done(desc, &walk, nbytes);
  1639. }
  1640. - kernel_fpu_end();
  1641. return err;
  1642. }
  1643. @@ -455,14 +455,14 @@
  1644. err = blkcipher_walk_virt(desc, &walk);
  1645. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1646. - kernel_fpu_begin();
  1647. while ((nbytes = walk.nbytes)) {
  1648. + kernel_fpu_begin();
  1649. aesni_cbc_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  1650. nbytes & AES_BLOCK_MASK, walk.iv);
  1651. + kernel_fpu_end();
  1652. nbytes &= AES_BLOCK_SIZE - 1;
  1653. err = blkcipher_walk_done(desc, &walk, nbytes);
  1654. }
  1655. - kernel_fpu_end();
  1656. return err;
  1657. }
  1658. @@ -514,18 +514,20 @@
  1659. err = blkcipher_walk_virt_block(desc, &walk, AES_BLOCK_SIZE);
  1660. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1661. - kernel_fpu_begin();
  1662. while ((nbytes = walk.nbytes) >= AES_BLOCK_SIZE) {
  1663. + kernel_fpu_begin();
  1664. aesni_ctr_enc_tfm(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  1665. nbytes & AES_BLOCK_MASK, walk.iv);
  1666. + kernel_fpu_end();
  1667. nbytes &= AES_BLOCK_SIZE - 1;
  1668. err = blkcipher_walk_done(desc, &walk, nbytes);
  1669. }
  1670. if (walk.nbytes) {
  1671. + kernel_fpu_begin();
  1672. ctr_crypt_final(ctx, &walk);
  1673. + kernel_fpu_end();
  1674. err = blkcipher_walk_done(desc, &walk, 0);
  1675. }
  1676. - kernel_fpu_end();
  1677. return err;
  1678. }
  1679. diff -Nur linux-4.4.13.orig/arch/x86/crypto/cast5_avx_glue.c linux-4.4.13/arch/x86/crypto/cast5_avx_glue.c
  1680. --- linux-4.4.13.orig/arch/x86/crypto/cast5_avx_glue.c 2016-06-08 03:14:51.000000000 +0200
  1681. +++ linux-4.4.13/arch/x86/crypto/cast5_avx_glue.c 2016-06-22 21:55:07.982523867 +0200
  1682. @@ -59,7 +59,7 @@
  1683. static int ecb_crypt(struct blkcipher_desc *desc, struct blkcipher_walk *walk,
  1684. bool enc)
  1685. {
  1686. - bool fpu_enabled = false;
  1687. + bool fpu_enabled;
  1688. struct cast5_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  1689. const unsigned int bsize = CAST5_BLOCK_SIZE;
  1690. unsigned int nbytes;
  1691. @@ -75,7 +75,7 @@
  1692. u8 *wsrc = walk->src.virt.addr;
  1693. u8 *wdst = walk->dst.virt.addr;
  1694. - fpu_enabled = cast5_fpu_begin(fpu_enabled, nbytes);
  1695. + fpu_enabled = cast5_fpu_begin(false, nbytes);
  1696. /* Process multi-block batch */
  1697. if (nbytes >= bsize * CAST5_PARALLEL_BLOCKS) {
  1698. @@ -103,10 +103,9 @@
  1699. } while (nbytes >= bsize);
  1700. done:
  1701. + cast5_fpu_end(fpu_enabled);
  1702. err = blkcipher_walk_done(desc, walk, nbytes);
  1703. }
  1704. -
  1705. - cast5_fpu_end(fpu_enabled);
  1706. return err;
  1707. }
  1708. @@ -227,7 +226,7 @@
  1709. static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1710. struct scatterlist *src, unsigned int nbytes)
  1711. {
  1712. - bool fpu_enabled = false;
  1713. + bool fpu_enabled;
  1714. struct blkcipher_walk walk;
  1715. int err;
  1716. @@ -236,12 +235,11 @@
  1717. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1718. while ((nbytes = walk.nbytes)) {
  1719. - fpu_enabled = cast5_fpu_begin(fpu_enabled, nbytes);
  1720. + fpu_enabled = cast5_fpu_begin(false, nbytes);
  1721. nbytes = __cbc_decrypt(desc, &walk);
  1722. + cast5_fpu_end(fpu_enabled);
  1723. err = blkcipher_walk_done(desc, &walk, nbytes);
  1724. }
  1725. -
  1726. - cast5_fpu_end(fpu_enabled);
  1727. return err;
  1728. }
  1729. @@ -311,7 +309,7 @@
  1730. static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  1731. struct scatterlist *src, unsigned int nbytes)
  1732. {
  1733. - bool fpu_enabled = false;
  1734. + bool fpu_enabled;
  1735. struct blkcipher_walk walk;
  1736. int err;
  1737. @@ -320,13 +318,12 @@
  1738. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  1739. while ((nbytes = walk.nbytes) >= CAST5_BLOCK_SIZE) {
  1740. - fpu_enabled = cast5_fpu_begin(fpu_enabled, nbytes);
  1741. + fpu_enabled = cast5_fpu_begin(false, nbytes);
  1742. nbytes = __ctr_crypt(desc, &walk);
  1743. + cast5_fpu_end(fpu_enabled);
  1744. err = blkcipher_walk_done(desc, &walk, nbytes);
  1745. }
  1746. - cast5_fpu_end(fpu_enabled);
  1747. -
  1748. if (walk.nbytes) {
  1749. ctr_crypt_final(desc, &walk);
  1750. err = blkcipher_walk_done(desc, &walk, 0);
  1751. diff -Nur linux-4.4.13.orig/arch/x86/crypto/glue_helper.c linux-4.4.13/arch/x86/crypto/glue_helper.c
  1752. --- linux-4.4.13.orig/arch/x86/crypto/glue_helper.c 2016-06-08 03:14:51.000000000 +0200
  1753. +++ linux-4.4.13/arch/x86/crypto/glue_helper.c 2016-06-22 21:55:07.982523867 +0200
  1754. @@ -39,7 +39,7 @@
  1755. void *ctx = crypto_blkcipher_ctx(desc->tfm);
  1756. const unsigned int bsize = 128 / 8;
  1757. unsigned int nbytes, i, func_bytes;
  1758. - bool fpu_enabled = false;
  1759. + bool fpu_enabled;
  1760. int err;
  1761. err = blkcipher_walk_virt(desc, walk);
  1762. @@ -49,7 +49,7 @@
  1763. u8 *wdst = walk->dst.virt.addr;
  1764. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  1765. - desc, fpu_enabled, nbytes);
  1766. + desc, false, nbytes);
  1767. for (i = 0; i < gctx->num_funcs; i++) {
  1768. func_bytes = bsize * gctx->funcs[i].num_blocks;
  1769. @@ -71,10 +71,10 @@
  1770. }
  1771. done:
  1772. + glue_fpu_end(fpu_enabled);
  1773. err = blkcipher_walk_done(desc, walk, nbytes);
  1774. }
  1775. - glue_fpu_end(fpu_enabled);
  1776. return err;
  1777. }
  1778. @@ -194,7 +194,7 @@
  1779. struct scatterlist *src, unsigned int nbytes)
  1780. {
  1781. const unsigned int bsize = 128 / 8;
  1782. - bool fpu_enabled = false;
  1783. + bool fpu_enabled;
  1784. struct blkcipher_walk walk;
  1785. int err;
  1786. @@ -203,12 +203,12 @@
  1787. while ((nbytes = walk.nbytes)) {
  1788. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  1789. - desc, fpu_enabled, nbytes);
  1790. + desc, false, nbytes);
  1791. nbytes = __glue_cbc_decrypt_128bit(gctx, desc, &walk);
  1792. + glue_fpu_end(fpu_enabled);
  1793. err = blkcipher_walk_done(desc, &walk, nbytes);
  1794. }
  1795. - glue_fpu_end(fpu_enabled);
  1796. return err;
  1797. }
  1798. EXPORT_SYMBOL_GPL(glue_cbc_decrypt_128bit);
  1799. @@ -277,7 +277,7 @@
  1800. struct scatterlist *src, unsigned int nbytes)
  1801. {
  1802. const unsigned int bsize = 128 / 8;
  1803. - bool fpu_enabled = false;
  1804. + bool fpu_enabled;
  1805. struct blkcipher_walk walk;
  1806. int err;
  1807. @@ -286,13 +286,12 @@
  1808. while ((nbytes = walk.nbytes) >= bsize) {
  1809. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  1810. - desc, fpu_enabled, nbytes);
  1811. + desc, false, nbytes);
  1812. nbytes = __glue_ctr_crypt_128bit(gctx, desc, &walk);
  1813. + glue_fpu_end(fpu_enabled);
  1814. err = blkcipher_walk_done(desc, &walk, nbytes);
  1815. }
  1816. - glue_fpu_end(fpu_enabled);
  1817. -
  1818. if (walk.nbytes) {
  1819. glue_ctr_crypt_final_128bit(
  1820. gctx->funcs[gctx->num_funcs - 1].fn_u.ctr, desc, &walk);
  1821. @@ -347,7 +346,7 @@
  1822. void *tweak_ctx, void *crypt_ctx)
  1823. {
  1824. const unsigned int bsize = 128 / 8;
  1825. - bool fpu_enabled = false;
  1826. + bool fpu_enabled;
  1827. struct blkcipher_walk walk;
  1828. int err;
  1829. @@ -360,21 +359,21 @@
  1830. /* set minimum length to bsize, for tweak_fn */
  1831. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  1832. - desc, fpu_enabled,
  1833. + desc, false,
  1834. nbytes < bsize ? bsize : nbytes);
  1835. -
  1836. /* calculate first value of T */
  1837. tweak_fn(tweak_ctx, walk.iv, walk.iv);
  1838. + glue_fpu_end(fpu_enabled);
  1839. while (nbytes) {
  1840. + fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  1841. + desc, false, nbytes);
  1842. nbytes = __glue_xts_crypt_128bit(gctx, crypt_ctx, desc, &walk);
  1843. + glue_fpu_end(fpu_enabled);
  1844. err = blkcipher_walk_done(desc, &walk, nbytes);
  1845. nbytes = walk.nbytes;
  1846. }
  1847. -
  1848. - glue_fpu_end(fpu_enabled);
  1849. -
  1850. return err;
  1851. }
  1852. EXPORT_SYMBOL_GPL(glue_xts_crypt_128bit);
  1853. diff -Nur linux-4.4.13.orig/arch/x86/entry/common.c linux-4.4.13/arch/x86/entry/common.c
  1854. --- linux-4.4.13.orig/arch/x86/entry/common.c 2016-06-08 03:14:51.000000000 +0200
  1855. +++ linux-4.4.13/arch/x86/entry/common.c 2016-06-22 21:55:07.982523867 +0200
  1856. @@ -220,7 +220,7 @@
  1857. #define EXIT_TO_USERMODE_LOOP_FLAGS \
  1858. (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
  1859. - _TIF_NEED_RESCHED | _TIF_USER_RETURN_NOTIFY)
  1860. + _TIF_NEED_RESCHED_MASK | _TIF_USER_RETURN_NOTIFY)
  1861. static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
  1862. {
  1863. @@ -236,9 +236,16 @@
  1864. /* We have work to do. */
  1865. local_irq_enable();
  1866. - if (cached_flags & _TIF_NEED_RESCHED)
  1867. + if (cached_flags & _TIF_NEED_RESCHED_MASK)
  1868. schedule();
  1869. +#ifdef ARCH_RT_DELAYS_SIGNAL_SEND
  1870. + if (unlikely(current->forced_info.si_signo)) {
  1871. + struct task_struct *t = current;
  1872. + force_sig_info(t->forced_info.si_signo, &t->forced_info, t);
  1873. + t->forced_info.si_signo = 0;
  1874. + }
  1875. +#endif
  1876. if (cached_flags & _TIF_UPROBE)
  1877. uprobe_notify_resume(regs);
  1878. diff -Nur linux-4.4.13.orig/arch/x86/entry/entry_32.S linux-4.4.13/arch/x86/entry/entry_32.S
  1879. --- linux-4.4.13.orig/arch/x86/entry/entry_32.S 2016-06-08 03:14:51.000000000 +0200
  1880. +++ linux-4.4.13/arch/x86/entry/entry_32.S 2016-06-22 21:55:07.982523867 +0200
  1881. @@ -278,8 +278,24 @@
  1882. ENTRY(resume_kernel)
  1883. DISABLE_INTERRUPTS(CLBR_ANY)
  1884. need_resched:
  1885. + # preempt count == 0 + NEED_RS set?
  1886. cmpl $0, PER_CPU_VAR(__preempt_count)
  1887. +#ifndef CONFIG_PREEMPT_LAZY
  1888. jnz restore_all
  1889. +#else
  1890. + jz test_int_off
  1891. +
  1892. + # atleast preempt count == 0 ?
  1893. + cmpl $_PREEMPT_ENABLED,PER_CPU_VAR(__preempt_count)
  1894. + jne restore_all
  1895. +
  1896. + cmpl $0,TI_preempt_lazy_count(%ebp) # non-zero preempt_lazy_count ?
  1897. + jnz restore_all
  1898. +
  1899. + testl $_TIF_NEED_RESCHED_LAZY, TI_flags(%ebp)
  1900. + jz restore_all
  1901. +test_int_off:
  1902. +#endif
  1903. testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off (exception path) ?
  1904. jz restore_all
  1905. call preempt_schedule_irq
  1906. diff -Nur linux-4.4.13.orig/arch/x86/entry/entry_64.S linux-4.4.13/arch/x86/entry/entry_64.S
  1907. --- linux-4.4.13.orig/arch/x86/entry/entry_64.S 2016-06-08 03:14:51.000000000 +0200
  1908. +++ linux-4.4.13/arch/x86/entry/entry_64.S 2016-06-22 21:55:07.982523867 +0200
  1909. @@ -579,7 +579,23 @@
  1910. bt $9, EFLAGS(%rsp) /* were interrupts off? */
  1911. jnc 1f
  1912. 0: cmpl $0, PER_CPU_VAR(__preempt_count)
  1913. +#ifndef CONFIG_PREEMPT_LAZY
  1914. jnz 1f
  1915. +#else
  1916. + jz do_preempt_schedule_irq
  1917. +
  1918. + # atleast preempt count == 0 ?
  1919. + cmpl $_PREEMPT_ENABLED,PER_CPU_VAR(__preempt_count)
  1920. + jnz 1f
  1921. +
  1922. + GET_THREAD_INFO(%rcx)
  1923. + cmpl $0, TI_preempt_lazy_count(%rcx)
  1924. + jnz 1f
  1925. +
  1926. + bt $TIF_NEED_RESCHED_LAZY,TI_flags(%rcx)
  1927. + jnc 1f
  1928. +do_preempt_schedule_irq:
  1929. +#endif
  1930. call preempt_schedule_irq
  1931. jmp 0b
  1932. 1:
  1933. @@ -867,6 +883,7 @@
  1934. jmp 2b
  1935. .previous
  1936. +#ifndef CONFIG_PREEMPT_RT_FULL
  1937. /* Call softirq on interrupt stack. Interrupts are off. */
  1938. ENTRY(do_softirq_own_stack)
  1939. pushq %rbp
  1940. @@ -879,6 +896,7 @@
  1941. decl PER_CPU_VAR(irq_count)
  1942. ret
  1943. END(do_softirq_own_stack)
  1944. +#endif
  1945. #ifdef CONFIG_XEN
  1946. idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
  1947. diff -Nur linux-4.4.13.orig/arch/x86/include/asm/preempt.h linux-4.4.13/arch/x86/include/asm/preempt.h
  1948. --- linux-4.4.13.orig/arch/x86/include/asm/preempt.h 2016-06-08 03:14:51.000000000 +0200
  1949. +++ linux-4.4.13/arch/x86/include/asm/preempt.h 2016-06-22 21:55:07.982523867 +0200
  1950. @@ -79,17 +79,33 @@
  1951. * a decrement which hits zero means we have no preempt_count and should
  1952. * reschedule.
  1953. */
  1954. -static __always_inline bool __preempt_count_dec_and_test(void)
  1955. +static __always_inline bool ____preempt_count_dec_and_test(void)
  1956. {
  1957. GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
  1958. }
  1959. +static __always_inline bool __preempt_count_dec_and_test(void)
  1960. +{
  1961. + if (____preempt_count_dec_and_test())
  1962. + return true;
  1963. +#ifdef CONFIG_PREEMPT_LAZY
  1964. + return test_thread_flag(TIF_NEED_RESCHED_LAZY);
  1965. +#else
  1966. + return false;
  1967. +#endif
  1968. +}
  1969. +
  1970. /*
  1971. * Returns true when we need to resched and can (barring IRQ state).
  1972. */
  1973. static __always_inline bool should_resched(int preempt_offset)
  1974. {
  1975. +#ifdef CONFIG_PREEMPT_LAZY
  1976. + return unlikely(raw_cpu_read_4(__preempt_count) == preempt_offset ||
  1977. + test_thread_flag(TIF_NEED_RESCHED_LAZY));
  1978. +#else
  1979. return unlikely(raw_cpu_read_4(__preempt_count) == preempt_offset);
  1980. +#endif
  1981. }
  1982. #ifdef CONFIG_PREEMPT
  1983. diff -Nur linux-4.4.13.orig/arch/x86/include/asm/signal.h linux-4.4.13/arch/x86/include/asm/signal.h
  1984. --- linux-4.4.13.orig/arch/x86/include/asm/signal.h 2016-06-08 03:14:51.000000000 +0200
  1985. +++ linux-4.4.13/arch/x86/include/asm/signal.h 2016-06-22 21:55:07.982523867 +0200
  1986. @@ -23,6 +23,19 @@
  1987. unsigned long sig[_NSIG_WORDS];
  1988. } sigset_t;
  1989. +/*
  1990. + * Because some traps use the IST stack, we must keep preemption
  1991. + * disabled while calling do_trap(), but do_trap() may call
  1992. + * force_sig_info() which will grab the signal spin_locks for the
  1993. + * task, which in PREEMPT_RT_FULL are mutexes. By defining
  1994. + * ARCH_RT_DELAYS_SIGNAL_SEND the force_sig_info() will set
  1995. + * TIF_NOTIFY_RESUME and set up the signal to be sent on exit of the
  1996. + * trap.
  1997. + */
  1998. +#if defined(CONFIG_PREEMPT_RT_FULL)
  1999. +#define ARCH_RT_DELAYS_SIGNAL_SEND
  2000. +#endif
  2001. +
  2002. #ifndef CONFIG_COMPAT
  2003. typedef sigset_t compat_sigset_t;
  2004. #endif
  2005. diff -Nur linux-4.4.13.orig/arch/x86/include/asm/stackprotector.h linux-4.4.13/arch/x86/include/asm/stackprotector.h
  2006. --- linux-4.4.13.orig/arch/x86/include/asm/stackprotector.h 2016-06-08 03:14:51.000000000 +0200
  2007. +++ linux-4.4.13/arch/x86/include/asm/stackprotector.h 2016-06-22 21:55:07.982523867 +0200
  2008. @@ -59,7 +59,7 @@
  2009. */
  2010. static __always_inline void boot_init_stack_canary(void)
  2011. {
  2012. - u64 canary;
  2013. + u64 uninitialized_var(canary);
  2014. u64 tsc;
  2015. #ifdef CONFIG_X86_64
  2016. @@ -70,8 +70,15 @@
  2017. * of randomness. The TSC only matters for very early init,
  2018. * there it already has some randomness on most systems. Later
  2019. * on during the bootup the random pool has true entropy too.
  2020. + *
  2021. + * For preempt-rt we need to weaken the randomness a bit, as
  2022. + * we can't call into the random generator from atomic context
  2023. + * due to locking constraints. We just leave canary
  2024. + * uninitialized and use the TSC based randomness on top of it.
  2025. */
  2026. +#ifndef CONFIG_PREEMPT_RT_FULL
  2027. get_random_bytes(&canary, sizeof(canary));
  2028. +#endif
  2029. tsc = rdtsc();
  2030. canary += tsc + (tsc << 32UL);
  2031. diff -Nur linux-4.4.13.orig/arch/x86/include/asm/thread_info.h linux-4.4.13/arch/x86/include/asm/thread_info.h
  2032. --- linux-4.4.13.orig/arch/x86/include/asm/thread_info.h 2016-06-08 03:14:51.000000000 +0200
  2033. +++ linux-4.4.13/arch/x86/include/asm/thread_info.h 2016-06-22 21:55:07.982523867 +0200
  2034. @@ -58,6 +58,8 @@
  2035. __u32 status; /* thread synchronous flags */
  2036. __u32 cpu; /* current CPU */
  2037. mm_segment_t addr_limit;
  2038. + int preempt_lazy_count; /* 0 => lazy preemptable
  2039. + <0 => BUG */
  2040. unsigned int sig_on_uaccess_error:1;
  2041. unsigned int uaccess_err:1; /* uaccess failed */
  2042. };
  2043. @@ -95,6 +97,7 @@
  2044. #define TIF_SYSCALL_EMU 6 /* syscall emulation active */
  2045. #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
  2046. #define TIF_SECCOMP 8 /* secure computing */
  2047. +#define TIF_NEED_RESCHED_LAZY 9 /* lazy rescheduling necessary */
  2048. #define TIF_USER_RETURN_NOTIFY 11 /* notify kernel of userspace return */
  2049. #define TIF_UPROBE 12 /* breakpointed or singlestepping */
  2050. #define TIF_NOTSC 16 /* TSC is not accessible in userland */
  2051. @@ -119,6 +122,7 @@
  2052. #define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU)
  2053. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  2054. #define _TIF_SECCOMP (1 << TIF_SECCOMP)
  2055. +#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)
  2056. #define _TIF_USER_RETURN_NOTIFY (1 << TIF_USER_RETURN_NOTIFY)
  2057. #define _TIF_UPROBE (1 << TIF_UPROBE)
  2058. #define _TIF_NOTSC (1 << TIF_NOTSC)
  2059. @@ -152,6 +156,8 @@
  2060. #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
  2061. #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
  2062. +#define _TIF_NEED_RESCHED_MASK (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)
  2063. +
  2064. #define STACK_WARN (THREAD_SIZE/8)
  2065. /*
  2066. diff -Nur linux-4.4.13.orig/arch/x86/include/asm/uv/uv_bau.h linux-4.4.13/arch/x86/include/asm/uv/uv_bau.h
  2067. --- linux-4.4.13.orig/arch/x86/include/asm/uv/uv_bau.h 2016-06-08 03:14:51.000000000 +0200
  2068. +++ linux-4.4.13/arch/x86/include/asm/uv/uv_bau.h 2016-06-22 21:55:07.982523867 +0200
  2069. @@ -615,9 +615,9 @@
  2070. cycles_t send_message;
  2071. cycles_t period_end;
  2072. cycles_t period_time;
  2073. - spinlock_t uvhub_lock;
  2074. - spinlock_t queue_lock;
  2075. - spinlock_t disable_lock;
  2076. + raw_spinlock_t uvhub_lock;
  2077. + raw_spinlock_t queue_lock;
  2078. + raw_spinlock_t disable_lock;
  2079. /* tunables */
  2080. int max_concurr;
  2081. int max_concurr_const;
  2082. @@ -776,15 +776,15 @@
  2083. * to be lowered below the current 'v'. atomic_add_unless can only stop
  2084. * on equal.
  2085. */
  2086. -static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
  2087. +static inline int atomic_inc_unless_ge(raw_spinlock_t *lock, atomic_t *v, int u)
  2088. {
  2089. - spin_lock(lock);
  2090. + raw_spin_lock(lock);
  2091. if (atomic_read(v) >= u) {
  2092. - spin_unlock(lock);
  2093. + raw_spin_unlock(lock);
  2094. return 0;
  2095. }
  2096. atomic_inc(v);
  2097. - spin_unlock(lock);
  2098. + raw_spin_unlock(lock);
  2099. return 1;
  2100. }
  2101. diff -Nur linux-4.4.13.orig/arch/x86/include/asm/uv/uv_hub.h linux-4.4.13/arch/x86/include/asm/uv/uv_hub.h
  2102. --- linux-4.4.13.orig/arch/x86/include/asm/uv/uv_hub.h 2016-06-08 03:14:51.000000000 +0200
  2103. +++ linux-4.4.13/arch/x86/include/asm/uv/uv_hub.h 2016-06-22 21:55:07.982523867 +0200
  2104. @@ -492,7 +492,7 @@
  2105. unsigned short nr_online_cpus;
  2106. unsigned short pnode;
  2107. short memory_nid;
  2108. - spinlock_t nmi_lock; /* obsolete, see uv_hub_nmi */
  2109. + raw_spinlock_t nmi_lock; /* obsolete, see uv_hub_nmi */
  2110. unsigned long nmi_count; /* obsolete, see uv_hub_nmi */
  2111. };
  2112. extern struct uv_blade_info *uv_blade_info;
  2113. diff -Nur linux-4.4.13.orig/arch/x86/Kconfig linux-4.4.13/arch/x86/Kconfig
  2114. --- linux-4.4.13.orig/arch/x86/Kconfig 2016-06-08 03:14:51.000000000 +0200
  2115. +++ linux-4.4.13/arch/x86/Kconfig 2016-06-22 21:55:07.986523867 +0200
  2116. @@ -17,6 +17,7 @@
  2117. ### Arch settings
  2118. config X86
  2119. def_bool y
  2120. + select HAVE_PREEMPT_LAZY
  2121. select ACPI_LEGACY_TABLES_LOOKUP if ACPI
  2122. select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
  2123. select ANON_INODES
  2124. @@ -212,8 +213,11 @@
  2125. def_bool y
  2126. depends on ISA_DMA_API
  2127. +config RWSEM_GENERIC_SPINLOCK
  2128. + def_bool PREEMPT_RT_FULL
  2129. +
  2130. config RWSEM_XCHGADD_ALGORITHM
  2131. - def_bool y
  2132. + def_bool !RWSEM_GENERIC_SPINLOCK && !PREEMPT_RT_FULL
  2133. config GENERIC_CALIBRATE_DELAY
  2134. def_bool y
  2135. @@ -848,7 +852,7 @@
  2136. config MAXSMP
  2137. bool "Enable Maximum number of SMP Processors and NUMA Nodes"
  2138. depends on X86_64 && SMP && DEBUG_KERNEL
  2139. - select CPUMASK_OFFSTACK
  2140. + select CPUMASK_OFFSTACK if !PREEMPT_RT_FULL
  2141. ---help---
  2142. Enable maximum number of CPUS and NUMA Nodes for this architecture.
  2143. If unsure, say N.
  2144. diff -Nur linux-4.4.13.orig/arch/x86/kernel/apic/io_apic.c linux-4.4.13/arch/x86/kernel/apic/io_apic.c
  2145. --- linux-4.4.13.orig/arch/x86/kernel/apic/io_apic.c 2016-06-08 03:14:51.000000000 +0200
  2146. +++ linux-4.4.13/arch/x86/kernel/apic/io_apic.c 2016-06-22 21:55:07.986523867 +0200
  2147. @@ -1711,7 +1711,8 @@
  2148. static inline bool ioapic_irqd_mask(struct irq_data *data)
  2149. {
  2150. /* If we are moving the irq we need to mask it */
  2151. - if (unlikely(irqd_is_setaffinity_pending(data))) {
  2152. + if (unlikely(irqd_is_setaffinity_pending(data) &&
  2153. + !irqd_irq_inprogress(data))) {
  2154. mask_ioapic_irq(data);
  2155. return true;
  2156. }
  2157. diff -Nur linux-4.4.13.orig/arch/x86/kernel/apic/x2apic_uv_x.c linux-4.4.13/arch/x86/kernel/apic/x2apic_uv_x.c
  2158. --- linux-4.4.13.orig/arch/x86/kernel/apic/x2apic_uv_x.c 2016-06-08 03:14:51.000000000 +0200
  2159. +++ linux-4.4.13/arch/x86/kernel/apic/x2apic_uv_x.c 2016-06-22 21:55:07.986523867 +0200
  2160. @@ -947,7 +947,7 @@
  2161. uv_blade_info[blade].pnode = pnode;
  2162. uv_blade_info[blade].nr_possible_cpus = 0;
  2163. uv_blade_info[blade].nr_online_cpus = 0;
  2164. - spin_lock_init(&uv_blade_info[blade].nmi_lock);
  2165. + raw_spin_lock_init(&uv_blade_info[blade].nmi_lock);
  2166. min_pnode = min(pnode, min_pnode);
  2167. max_pnode = max(pnode, max_pnode);
  2168. blade++;
  2169. diff -Nur linux-4.4.13.orig/arch/x86/kernel/asm-offsets.c linux-4.4.13/arch/x86/kernel/asm-offsets.c
  2170. --- linux-4.4.13.orig/arch/x86/kernel/asm-offsets.c 2016-06-08 03:14:51.000000000 +0200
  2171. +++ linux-4.4.13/arch/x86/kernel/asm-offsets.c 2016-06-22 21:55:07.986523867 +0200
  2172. @@ -32,6 +32,7 @@
  2173. OFFSET(TI_flags, thread_info, flags);
  2174. OFFSET(TI_status, thread_info, status);
  2175. OFFSET(TI_addr_limit, thread_info, addr_limit);
  2176. + OFFSET(TI_preempt_lazy_count, thread_info, preempt_lazy_count);
  2177. BLANK();
  2178. OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
  2179. @@ -89,4 +90,5 @@
  2180. BLANK();
  2181. DEFINE(PTREGS_SIZE, sizeof(struct pt_regs));
  2182. + DEFINE(_PREEMPT_ENABLED, PREEMPT_ENABLED);
  2183. }
  2184. diff -Nur linux-4.4.13.orig/arch/x86/kernel/cpu/mcheck/mce.c linux-4.4.13/arch/x86/kernel/cpu/mcheck/mce.c
  2185. --- linux-4.4.13.orig/arch/x86/kernel/cpu/mcheck/mce.c 2016-06-08 03:14:51.000000000 +0200
  2186. +++ linux-4.4.13/arch/x86/kernel/cpu/mcheck/mce.c 2016-06-22 21:55:07.986523867 +0200
  2187. @@ -41,6 +41,8 @@
  2188. #include <linux/debugfs.h>
  2189. #include <linux/irq_work.h>
  2190. #include <linux/export.h>
  2191. +#include <linux/jiffies.h>
  2192. +#include <linux/work-simple.h>
  2193. #include <asm/processor.h>
  2194. #include <asm/traps.h>
  2195. @@ -1236,7 +1238,7 @@
  2196. static unsigned long check_interval = INITIAL_CHECK_INTERVAL;
  2197. static DEFINE_PER_CPU(unsigned long, mce_next_interval); /* in jiffies */
  2198. -static DEFINE_PER_CPU(struct timer_list, mce_timer);
  2199. +static DEFINE_PER_CPU(struct hrtimer, mce_timer);
  2200. static unsigned long mce_adjust_timer_default(unsigned long interval)
  2201. {
  2202. @@ -1245,32 +1247,18 @@
  2203. static unsigned long (*mce_adjust_timer)(unsigned long interval) = mce_adjust_timer_default;
  2204. -static void __restart_timer(struct timer_list *t, unsigned long interval)
  2205. +static enum hrtimer_restart __restart_timer(struct hrtimer *timer, unsigned long interval)
  2206. {
  2207. - unsigned long when = jiffies + interval;
  2208. - unsigned long flags;
  2209. -
  2210. - local_irq_save(flags);
  2211. -
  2212. - if (timer_pending(t)) {
  2213. - if (time_before(when, t->expires))
  2214. - mod_timer_pinned(t, when);
  2215. - } else {
  2216. - t->expires = round_jiffies(when);
  2217. - add_timer_on(t, smp_processor_id());
  2218. - }
  2219. -
  2220. - local_irq_restore(flags);
  2221. + if (!interval)
  2222. + return HRTIMER_NORESTART;
  2223. + hrtimer_forward_now(timer, ns_to_ktime(jiffies_to_nsecs(interval)));
  2224. + return HRTIMER_RESTART;
  2225. }
  2226. -static void mce_timer_fn(unsigned long data)
  2227. +static enum hrtimer_restart mce_timer_fn(struct hrtimer *timer)
  2228. {
  2229. - struct timer_list *t = this_cpu_ptr(&mce_timer);
  2230. - int cpu = smp_processor_id();
  2231. unsigned long iv;
  2232. - WARN_ON(cpu != data);
  2233. -
  2234. iv = __this_cpu_read(mce_next_interval);
  2235. if (mce_available(this_cpu_ptr(&cpu_info))) {
  2236. @@ -1293,7 +1281,7 @@
  2237. done:
  2238. __this_cpu_write(mce_next_interval, iv);
  2239. - __restart_timer(t, iv);
  2240. + return __restart_timer(timer, iv);
  2241. }
  2242. /*
  2243. @@ -1301,7 +1289,7 @@
  2244. */
  2245. void mce_timer_kick(unsigned long interval)
  2246. {
  2247. - struct timer_list *t = this_cpu_ptr(&mce_timer);
  2248. + struct hrtimer *t = this_cpu_ptr(&mce_timer);
  2249. unsigned long iv = __this_cpu_read(mce_next_interval);
  2250. __restart_timer(t, interval);
  2251. @@ -1316,7 +1304,7 @@
  2252. int cpu;
  2253. for_each_online_cpu(cpu)
  2254. - del_timer_sync(&per_cpu(mce_timer, cpu));
  2255. + hrtimer_cancel(&per_cpu(mce_timer, cpu));
  2256. }
  2257. static void mce_do_trigger(struct work_struct *work)
  2258. @@ -1326,6 +1314,56 @@
  2259. static DECLARE_WORK(mce_trigger_work, mce_do_trigger);
  2260. +static void __mce_notify_work(struct swork_event *event)
  2261. +{
  2262. + /* Not more than two messages every minute */
  2263. + static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
  2264. +
  2265. + /* wake processes polling /dev/mcelog */
  2266. + wake_up_interruptible(&mce_chrdev_wait);
  2267. +
  2268. + /*
  2269. + * There is no risk of missing notifications because
  2270. + * work_pending is always cleared before the function is
  2271. + * executed.
  2272. + */
  2273. + if (mce_helper[0] && !work_pending(&mce_trigger_work))
  2274. + schedule_work(&mce_trigger_work);
  2275. +
  2276. + if (__ratelimit(&ratelimit))
  2277. + pr_info(HW_ERR "Machine check events logged\n");
  2278. +}
  2279. +
  2280. +#ifdef CONFIG_PREEMPT_RT_FULL
  2281. +static bool notify_work_ready __read_mostly;
  2282. +static struct swork_event notify_work;
  2283. +
  2284. +static int mce_notify_work_init(void)
  2285. +{
  2286. + int err;
  2287. +
  2288. + err = swork_get();
  2289. + if (err)
  2290. + return err;
  2291. +
  2292. + INIT_SWORK(&notify_work, __mce_notify_work);
  2293. + notify_work_ready = true;
  2294. + return 0;
  2295. +}
  2296. +
  2297. +static void mce_notify_work(void)
  2298. +{
  2299. + if (notify_work_ready)
  2300. + swork_queue(&notify_work);
  2301. +}
  2302. +#else
  2303. +static void mce_notify_work(void)
  2304. +{
  2305. + __mce_notify_work(NULL);
  2306. +}
  2307. +static inline int mce_notify_work_init(void) { return 0; }
  2308. +#endif
  2309. +
  2310. /*
  2311. * Notify the user(s) about new machine check events.
  2312. * Can be called from interrupt context, but not from machine check/NMI
  2313. @@ -1333,19 +1371,8 @@
  2314. */
  2315. int mce_notify_irq(void)
  2316. {
  2317. - /* Not more than two messages every minute */
  2318. - static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
  2319. -
  2320. if (test_and_clear_bit(0, &mce_need_notify)) {
  2321. - /* wake processes polling /dev/mcelog */
  2322. - wake_up_interruptible(&mce_chrdev_wait);
  2323. -
  2324. - if (mce_helper[0])
  2325. - schedule_work(&mce_trigger_work);
  2326. -
  2327. - if (__ratelimit(&ratelimit))
  2328. - pr_info(HW_ERR "Machine check events logged\n");
  2329. -
  2330. + mce_notify_work();
  2331. return 1;
  2332. }
  2333. return 0;
  2334. @@ -1639,7 +1666,7 @@
  2335. }
  2336. }
  2337. -static void mce_start_timer(unsigned int cpu, struct timer_list *t)
  2338. +static void mce_start_timer(unsigned int cpu, struct hrtimer *t)
  2339. {
  2340. unsigned long iv = check_interval * HZ;
  2341. @@ -1648,16 +1675,17 @@
  2342. per_cpu(mce_next_interval, cpu) = iv;
  2343. - t->expires = round_jiffies(jiffies + iv);
  2344. - add_timer_on(t, cpu);
  2345. + hrtimer_start_range_ns(t, ns_to_ktime(jiffies_to_usecs(iv) * 1000ULL),
  2346. + 0, HRTIMER_MODE_REL_PINNED);
  2347. }
  2348. static void __mcheck_cpu_init_timer(void)
  2349. {
  2350. - struct timer_list *t = this_cpu_ptr(&mce_timer);
  2351. + struct hrtimer *t = this_cpu_ptr(&mce_timer);
  2352. unsigned int cpu = smp_processor_id();
  2353. - setup_timer(t, mce_timer_fn, cpu);
  2354. + hrtimer_init(t, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  2355. + t->function = mce_timer_fn;
  2356. mce_start_timer(cpu, t);
  2357. }
  2358. @@ -2376,6 +2404,8 @@
  2359. if (!mce_available(raw_cpu_ptr(&cpu_info)))
  2360. return;
  2361. + hrtimer_cancel(this_cpu_ptr(&mce_timer));
  2362. +
  2363. if (!(action & CPU_TASKS_FROZEN))
  2364. cmci_clear();
  2365. @@ -2398,6 +2428,7 @@
  2366. if (b->init)
  2367. wrmsrl(MSR_IA32_MCx_CTL(i), b->ctl);
  2368. }
  2369. + __mcheck_cpu_init_timer();
  2370. }
  2371. /* Get notified when a cpu comes on/off. Be hotplug friendly. */
  2372. @@ -2405,7 +2436,6 @@
  2373. mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
  2374. {
  2375. unsigned int cpu = (unsigned long)hcpu;
  2376. - struct timer_list *t = &per_cpu(mce_timer, cpu);
  2377. switch (action & ~CPU_TASKS_FROZEN) {
  2378. case CPU_ONLINE:
  2379. @@ -2425,11 +2455,9 @@
  2380. break;
  2381. case CPU_DOWN_PREPARE:
  2382. smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
  2383. - del_timer_sync(t);
  2384. break;
  2385. case CPU_DOWN_FAILED:
  2386. smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
  2387. - mce_start_timer(cpu, t);
  2388. break;
  2389. }
  2390. @@ -2468,6 +2496,10 @@
  2391. goto err_out;
  2392. }
  2393. + err = mce_notify_work_init();
  2394. + if (err)
  2395. + goto err_out;
  2396. +
  2397. if (!zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL)) {
  2398. err = -ENOMEM;
  2399. goto err_out;
  2400. diff -Nur linux-4.4.13.orig/arch/x86/kernel/cpu/perf_event_intel_rapl.c linux-4.4.13/arch/x86/kernel/cpu/perf_event_intel_rapl.c
  2401. --- linux-4.4.13.orig/arch/x86/kernel/cpu/perf_event_intel_rapl.c 2016-06-08 03:14:51.000000000 +0200
  2402. +++ linux-4.4.13/arch/x86/kernel/cpu/perf_event_intel_rapl.c 2016-06-22 21:55:07.986523867 +0200
  2403. @@ -117,7 +117,7 @@
  2404. };
  2405. struct rapl_pmu {
  2406. - spinlock_t lock;
  2407. + raw_spinlock_t lock;
  2408. int n_active; /* number of active events */
  2409. struct list_head active_list;
  2410. struct pmu *pmu; /* pointer to rapl_pmu_class */
  2411. @@ -220,13 +220,13 @@
  2412. if (!pmu->n_active)
  2413. return HRTIMER_NORESTART;
  2414. - spin_lock_irqsave(&pmu->lock, flags);
  2415. + raw_spin_lock_irqsave(&pmu->lock, flags);
  2416. list_for_each_entry(event, &pmu->active_list, active_entry) {
  2417. rapl_event_update(event);
  2418. }
  2419. - spin_unlock_irqrestore(&pmu->lock, flags);
  2420. + raw_spin_unlock_irqrestore(&pmu->lock, flags);
  2421. hrtimer_forward_now(hrtimer, pmu->timer_interval);
  2422. @@ -263,9 +263,9 @@
  2423. struct rapl_pmu *pmu = __this_cpu_read(rapl_pmu);
  2424. unsigned long flags;
  2425. - spin_lock_irqsave(&pmu->lock, flags);
  2426. + raw_spin_lock_irqsave(&pmu->lock, flags);
  2427. __rapl_pmu_event_start(pmu, event);
  2428. - spin_unlock_irqrestore(&pmu->lock, flags);
  2429. + raw_spin_unlock_irqrestore(&pmu->lock, flags);
  2430. }
  2431. static void rapl_pmu_event_stop(struct perf_event *event, int mode)
  2432. @@ -274,7 +274,7 @@
  2433. struct hw_perf_event *hwc = &event->hw;
  2434. unsigned long flags;
  2435. - spin_lock_irqsave(&pmu->lock, flags);
  2436. + raw_spin_lock_irqsave(&pmu->lock, flags);
  2437. /* mark event as deactivated and stopped */
  2438. if (!(hwc->state & PERF_HES_STOPPED)) {
  2439. @@ -299,7 +299,7 @@
  2440. hwc->state |= PERF_HES_UPTODATE;
  2441. }
  2442. - spin_unlock_irqrestore(&pmu->lock, flags);
  2443. + raw_spin_unlock_irqrestore(&pmu->lock, flags);
  2444. }
  2445. static int rapl_pmu_event_add(struct perf_event *event, int mode)
  2446. @@ -308,14 +308,14 @@
  2447. struct hw_perf_event *hwc = &event->hw;
  2448. unsigned long flags;
  2449. - spin_lock_irqsave(&pmu->lock, flags);
  2450. + raw_spin_lock_irqsave(&pmu->lock, flags);
  2451. hwc->state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
  2452. if (mode & PERF_EF_START)
  2453. __rapl_pmu_event_start(pmu, event);
  2454. - spin_unlock_irqrestore(&pmu->lock, flags);
  2455. + raw_spin_unlock_irqrestore(&pmu->lock, flags);
  2456. return 0;
  2457. }
  2458. @@ -603,7 +603,7 @@
  2459. pmu = kzalloc_node(sizeof(*pmu), GFP_KERNEL, cpu_to_node(cpu));
  2460. if (!pmu)
  2461. return -1;
  2462. - spin_lock_init(&pmu->lock);
  2463. + raw_spin_lock_init(&pmu->lock);
  2464. INIT_LIST_HEAD(&pmu->active_list);
  2465. diff -Nur linux-4.4.13.orig/arch/x86/kernel/dumpstack_32.c linux-4.4.13/arch/x86/kernel/dumpstack_32.c
  2466. --- linux-4.4.13.orig/arch/x86/kernel/dumpstack_32.c 2016-06-08 03:14:51.000000000 +0200
  2467. +++ linux-4.4.13/arch/x86/kernel/dumpstack_32.c 2016-06-22 21:55:07.986523867 +0200
  2468. @@ -42,7 +42,7 @@
  2469. unsigned long *stack, unsigned long bp,
  2470. const struct stacktrace_ops *ops, void *data)
  2471. {
  2472. - const unsigned cpu = get_cpu();
  2473. + const unsigned cpu = get_cpu_light();
  2474. int graph = 0;
  2475. u32 *prev_esp;
  2476. @@ -86,7 +86,7 @@
  2477. break;
  2478. touch_nmi_watchdog();
  2479. }
  2480. - put_cpu();
  2481. + put_cpu_light();
  2482. }
  2483. EXPORT_SYMBOL(dump_trace);
  2484. diff -Nur linux-4.4.13.orig/arch/x86/kernel/dumpstack_64.c linux-4.4.13/arch/x86/kernel/dumpstack_64.c
  2485. --- linux-4.4.13.orig/arch/x86/kernel/dumpstack_64.c 2016-06-08 03:14:51.000000000 +0200
  2486. +++ linux-4.4.13/arch/x86/kernel/dumpstack_64.c 2016-06-22 21:55:07.986523867 +0200
  2487. @@ -152,7 +152,7 @@
  2488. unsigned long *stack, unsigned long bp,
  2489. const struct stacktrace_ops *ops, void *data)
  2490. {
  2491. - const unsigned cpu = get_cpu();
  2492. + const unsigned cpu = get_cpu_light();
  2493. struct thread_info *tinfo;
  2494. unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
  2495. unsigned long dummy;
  2496. @@ -241,7 +241,7 @@
  2497. * This handles the process stack:
  2498. */
  2499. bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
  2500. - put_cpu();
  2501. + put_cpu_light();
  2502. }
  2503. EXPORT_SYMBOL(dump_trace);
  2504. @@ -255,7 +255,7 @@
  2505. int cpu;
  2506. int i;
  2507. - preempt_disable();
  2508. + migrate_disable();
  2509. cpu = smp_processor_id();
  2510. irq_stack_end = (unsigned long *)(per_cpu(irq_stack_ptr, cpu));
  2511. @@ -291,7 +291,7 @@
  2512. pr_cont(" %016lx", *stack++);
  2513. touch_nmi_watchdog();
  2514. }
  2515. - preempt_enable();
  2516. + migrate_enable();
  2517. pr_cont("\n");
  2518. show_trace_log_lvl(task, regs, sp, bp, log_lvl);
  2519. diff -Nur linux-4.4.13.orig/arch/x86/kernel/irq_32.c linux-4.4.13/arch/x86/kernel/irq_32.c
  2520. --- linux-4.4.13.orig/arch/x86/kernel/irq_32.c 2016-06-08 03:14:51.000000000 +0200
  2521. +++ linux-4.4.13/arch/x86/kernel/irq_32.c 2016-06-22 21:55:07.986523867 +0200
  2522. @@ -128,6 +128,7 @@
  2523. cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
  2524. }
  2525. +#ifndef CONFIG_PREEMPT_RT_FULL
  2526. void do_softirq_own_stack(void)
  2527. {
  2528. struct thread_info *curstk;
  2529. @@ -146,6 +147,7 @@
  2530. call_on_stack(__do_softirq, isp);
  2531. }
  2532. +#endif
  2533. bool handle_irq(struct irq_desc *desc, struct pt_regs *regs)
  2534. {
  2535. diff -Nur linux-4.4.13.orig/arch/x86/kernel/kvm.c linux-4.4.13/arch/x86/kernel/kvm.c
  2536. --- linux-4.4.13.orig/arch/x86/kernel/kvm.c 2016-06-08 03:14:51.000000000 +0200
  2537. +++ linux-4.4.13/arch/x86/kernel/kvm.c 2016-06-22 21:55:07.986523867 +0200
  2538. @@ -36,6 +36,7 @@
  2539. #include <linux/kprobes.h>
  2540. #include <linux/debugfs.h>
  2541. #include <linux/nmi.h>
  2542. +#include <linux/swait.h>
  2543. #include <asm/timer.h>
  2544. #include <asm/cpu.h>
  2545. #include <asm/traps.h>
  2546. @@ -91,14 +92,14 @@
  2547. struct kvm_task_sleep_node {
  2548. struct hlist_node link;
  2549. - wait_queue_head_t wq;
  2550. + struct swait_queue_head wq;
  2551. u32 token;
  2552. int cpu;
  2553. bool halted;
  2554. };
  2555. static struct kvm_task_sleep_head {
  2556. - spinlock_t lock;
  2557. + raw_spinlock_t lock;
  2558. struct hlist_head list;
  2559. } async_pf_sleepers[KVM_TASK_SLEEP_HASHSIZE];
  2560. @@ -122,17 +123,17 @@
  2561. u32 key = hash_32(token, KVM_TASK_SLEEP_HASHBITS);
  2562. struct kvm_task_sleep_head *b = &async_pf_sleepers[key];
  2563. struct kvm_task_sleep_node n, *e;
  2564. - DEFINE_WAIT(wait);
  2565. + DECLARE_SWAITQUEUE(wait);
  2566. rcu_irq_enter();
  2567. - spin_lock(&b->lock);
  2568. + raw_spin_lock(&b->lock);
  2569. e = _find_apf_task(b, token);
  2570. if (e) {
  2571. /* dummy entry exist -> wake up was delivered ahead of PF */
  2572. hlist_del(&e->link);
  2573. kfree(e);
  2574. - spin_unlock(&b->lock);
  2575. + raw_spin_unlock(&b->lock);
  2576. rcu_irq_exit();
  2577. return;
  2578. @@ -141,13 +142,13 @@
  2579. n.token = token;
  2580. n.cpu = smp_processor_id();
  2581. n.halted = is_idle_task(current) || preempt_count() > 1;
  2582. - init_waitqueue_head(&n.wq);
  2583. + init_swait_queue_head(&n.wq);
  2584. hlist_add_head(&n.link, &b->list);
  2585. - spin_unlock(&b->lock);
  2586. + raw_spin_unlock(&b->lock);
  2587. for (;;) {
  2588. if (!n.halted)
  2589. - prepare_to_wait(&n.wq, &wait, TASK_UNINTERRUPTIBLE);
  2590. + prepare_to_swait(&n.wq, &wait, TASK_UNINTERRUPTIBLE);
  2591. if (hlist_unhashed(&n.link))
  2592. break;
  2593. @@ -166,7 +167,7 @@
  2594. }
  2595. }
  2596. if (!n.halted)
  2597. - finish_wait(&n.wq, &wait);
  2598. + finish_swait(&n.wq, &wait);
  2599. rcu_irq_exit();
  2600. return;
  2601. @@ -178,8 +179,8 @@
  2602. hlist_del_init(&n->link);
  2603. if (n->halted)
  2604. smp_send_reschedule(n->cpu);
  2605. - else if (waitqueue_active(&n->wq))
  2606. - wake_up(&n->wq);
  2607. + else if (swait_active(&n->wq))
  2608. + swake_up(&n->wq);
  2609. }
  2610. static void apf_task_wake_all(void)
  2611. @@ -189,14 +190,14 @@
  2612. for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++) {
  2613. struct hlist_node *p, *next;
  2614. struct kvm_task_sleep_head *b = &async_pf_sleepers[i];
  2615. - spin_lock(&b->lock);
  2616. + raw_spin_lock(&b->lock);
  2617. hlist_for_each_safe(p, next, &b->list) {
  2618. struct kvm_task_sleep_node *n =
  2619. hlist_entry(p, typeof(*n), link);
  2620. if (n->cpu == smp_processor_id())
  2621. apf_task_wake_one(n);
  2622. }
  2623. - spin_unlock(&b->lock);
  2624. + raw_spin_unlock(&b->lock);
  2625. }
  2626. }
  2627. @@ -212,7 +213,7 @@
  2628. }
  2629. again:
  2630. - spin_lock(&b->lock);
  2631. + raw_spin_lock(&b->lock);
  2632. n = _find_apf_task(b, token);
  2633. if (!n) {
  2634. /*
  2635. @@ -225,17 +226,17 @@
  2636. * Allocation failed! Busy wait while other cpu
  2637. * handles async PF.
  2638. */
  2639. - spin_unlock(&b->lock);
  2640. + raw_spin_unlock(&b->lock);
  2641. cpu_relax();
  2642. goto again;
  2643. }
  2644. n->token = token;
  2645. n->cpu = smp_processor_id();
  2646. - init_waitqueue_head(&n->wq);
  2647. + init_swait_queue_head(&n->wq);
  2648. hlist_add_head(&n->link, &b->list);
  2649. } else
  2650. apf_task_wake_one(n);
  2651. - spin_unlock(&b->lock);
  2652. + raw_spin_unlock(&b->lock);
  2653. return;
  2654. }
  2655. EXPORT_SYMBOL_GPL(kvm_async_pf_task_wake);
  2656. @@ -486,7 +487,7 @@
  2657. paravirt_ops_setup();
  2658. register_reboot_notifier(&kvm_pv_reboot_nb);
  2659. for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
  2660. - spin_lock_init(&async_pf_sleepers[i].lock);
  2661. + raw_spin_lock_init(&async_pf_sleepers[i].lock);
  2662. if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
  2663. x86_init.irqs.trap_init = kvm_apf_trap_init;
  2664. diff -Nur linux-4.4.13.orig/arch/x86/kernel/nmi.c linux-4.4.13/arch/x86/kernel/nmi.c
  2665. --- linux-4.4.13.orig/arch/x86/kernel/nmi.c 2016-06-08 03:14:51.000000000 +0200
  2666. +++ linux-4.4.13/arch/x86/kernel/nmi.c 2016-06-22 21:55:07.986523867 +0200
  2667. @@ -231,7 +231,7 @@
  2668. #endif
  2669. if (panic_on_unrecovered_nmi)
  2670. - panic("NMI: Not continuing");
  2671. + nmi_panic(regs, "NMI: Not continuing");
  2672. pr_emerg("Dazed and confused, but trying to continue\n");
  2673. @@ -255,8 +255,16 @@
  2674. reason, smp_processor_id());
  2675. show_regs(regs);
  2676. - if (panic_on_io_nmi)
  2677. - panic("NMI IOCK error: Not continuing");
  2678. + if (panic_on_io_nmi) {
  2679. + nmi_panic(regs, "NMI IOCK error: Not continuing");
  2680. +
  2681. + /*
  2682. + * If we end up here, it means we have received an NMI while
  2683. + * processing panic(). Simply return without delaying and
  2684. + * re-enabling NMIs.
  2685. + */
  2686. + return;
  2687. + }
  2688. /* Re-enable the IOCK line, wait for a few seconds */
  2689. reason = (reason & NMI_REASON_CLEAR_MASK) | NMI_REASON_CLEAR_IOCHK;
  2690. @@ -297,7 +305,7 @@
  2691. pr_emerg("Do you have a strange power saving mode enabled?\n");
  2692. if (unknown_nmi_panic || panic_on_unrecovered_nmi)
  2693. - panic("NMI: Not continuing");
  2694. + nmi_panic(regs, "NMI: Not continuing");
  2695. pr_emerg("Dazed and confused, but trying to continue\n");
  2696. }
  2697. diff -Nur linux-4.4.13.orig/arch/x86/kernel/process_32.c linux-4.4.13/arch/x86/kernel/process_32.c
  2698. --- linux-4.4.13.orig/arch/x86/kernel/process_32.c 2016-06-08 03:14:51.000000000 +0200
  2699. +++ linux-4.4.13/arch/x86/kernel/process_32.c 2016-06-22 21:55:07.986523867 +0200
  2700. @@ -35,6 +35,7 @@
  2701. #include <linux/uaccess.h>
  2702. #include <linux/io.h>
  2703. #include <linux/kdebug.h>
  2704. +#include <linux/highmem.h>
  2705. #include <asm/pgtable.h>
  2706. #include <asm/ldt.h>
  2707. @@ -210,6 +211,35 @@
  2708. }
  2709. EXPORT_SYMBOL_GPL(start_thread);
  2710. +#ifdef CONFIG_PREEMPT_RT_FULL
  2711. +static void switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p)
  2712. +{
  2713. + int i;
  2714. +
  2715. + /*
  2716. + * Clear @prev's kmap_atomic mappings
  2717. + */
  2718. + for (i = 0; i < prev_p->kmap_idx; i++) {
  2719. + int idx = i + KM_TYPE_NR * smp_processor_id();
  2720. + pte_t *ptep = kmap_pte - idx;
  2721. +
  2722. + kpte_clear_flush(ptep, __fix_to_virt(FIX_KMAP_BEGIN + idx));
  2723. + }
  2724. + /*
  2725. + * Restore @next_p's kmap_atomic mappings
  2726. + */
  2727. + for (i = 0; i < next_p->kmap_idx; i++) {
  2728. + int idx = i + KM_TYPE_NR * smp_processor_id();
  2729. +
  2730. + if (!pte_none(next_p->kmap_pte[i]))
  2731. + set_pte(kmap_pte - idx, next_p->kmap_pte[i]);
  2732. + }
  2733. +}
  2734. +#else
  2735. +static inline void
  2736. +switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p) { }
  2737. +#endif
  2738. +
  2739. /*
  2740. * switch_to(x,y) should switch tasks from x to y.
  2741. @@ -286,6 +316,8 @@
  2742. task_thread_info(next_p)->flags & _TIF_WORK_CTXSW_NEXT))
  2743. __switch_to_xtra(prev_p, next_p, tss);
  2744. + switch_kmaps(prev_p, next_p);
  2745. +
  2746. /*
  2747. * Leave lazy mode, flushing any hypercalls made here.
  2748. * This must be done before restoring TLS segments so
  2749. diff -Nur linux-4.4.13.orig/arch/x86/kernel/reboot.c linux-4.4.13/arch/x86/kernel/reboot.c
  2750. --- linux-4.4.13.orig/arch/x86/kernel/reboot.c 2016-06-08 03:14:51.000000000 +0200
  2751. +++ linux-4.4.13/arch/x86/kernel/reboot.c 2016-06-22 21:55:07.986523867 +0200
  2752. @@ -726,6 +726,7 @@
  2753. static nmi_shootdown_cb shootdown_callback;
  2754. static atomic_t waiting_for_crash_ipi;
  2755. +static int crash_ipi_issued;
  2756. static int crash_nmi_callback(unsigned int val, struct pt_regs *regs)
  2757. {
  2758. @@ -788,6 +789,9 @@
  2759. smp_send_nmi_allbutself();
  2760. + /* Kick CPUs looping in NMI context. */
  2761. + WRITE_ONCE(crash_ipi_issued, 1);
  2762. +
  2763. msecs = 1000; /* Wait at most a second for the other cpus to stop */
  2764. while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
  2765. mdelay(1);
  2766. @@ -796,6 +800,22 @@
  2767. /* Leave the nmi callback set */
  2768. }
  2769. +
  2770. +/* Override the weak function in kernel/panic.c */
  2771. +void nmi_panic_self_stop(struct pt_regs *regs)
  2772. +{
  2773. + while (1) {
  2774. + /*
  2775. + * Wait for the crash dumping IPI to be issued, and then
  2776. + * call its callback directly.
  2777. + */
  2778. + if (READ_ONCE(crash_ipi_issued))
  2779. + crash_nmi_callback(0, regs); /* Don't return */
  2780. +
  2781. + cpu_relax();
  2782. + }
  2783. +}
  2784. +
  2785. #else /* !CONFIG_SMP */
  2786. void nmi_shootdown_cpus(nmi_shootdown_cb callback)
  2787. {
  2788. diff -Nur linux-4.4.13.orig/arch/x86/kvm/lapic.c linux-4.4.13/arch/x86/kvm/lapic.c
  2789. --- linux-4.4.13.orig/arch/x86/kvm/lapic.c 2016-06-08 03:14:51.000000000 +0200
  2790. +++ linux-4.4.13/arch/x86/kvm/lapic.c 2016-06-22 21:55:07.986523867 +0200
  2791. @@ -1195,7 +1195,7 @@
  2792. static void apic_timer_expired(struct kvm_lapic *apic)
  2793. {
  2794. struct kvm_vcpu *vcpu = apic->vcpu;
  2795. - wait_queue_head_t *q = &vcpu->wq;
  2796. + struct swait_queue_head *q = &vcpu->wq;
  2797. struct kvm_timer *ktimer = &apic->lapic_timer;
  2798. if (atomic_read(&apic->lapic_timer.pending))
  2799. @@ -1204,8 +1204,8 @@
  2800. atomic_inc(&apic->lapic_timer.pending);
  2801. kvm_set_pending_timer(vcpu);
  2802. - if (waitqueue_active(q))
  2803. - wake_up_interruptible(q);
  2804. + if (swait_active(q))
  2805. + swake_up(q);
  2806. if (apic_lvtt_tscdeadline(apic))
  2807. ktimer->expired_tscdeadline = ktimer->tscdeadline;
  2808. @@ -1801,6 +1801,7 @@
  2809. hrtimer_init(&apic->lapic_timer.timer, CLOCK_MONOTONIC,
  2810. HRTIMER_MODE_ABS);
  2811. apic->lapic_timer.timer.function = apic_timer_fn;
  2812. + apic->lapic_timer.timer.irqsafe = 1;
  2813. /*
  2814. * APIC is created enabled. This will prevent kvm_lapic_set_base from
  2815. diff -Nur linux-4.4.13.orig/arch/x86/kvm/x86.c linux-4.4.13/arch/x86/kvm/x86.c
  2816. --- linux-4.4.13.orig/arch/x86/kvm/x86.c 2016-06-08 03:14:51.000000000 +0200
  2817. +++ linux-4.4.13/arch/x86/kvm/x86.c 2016-06-22 21:55:07.990523867 +0200
  2818. @@ -5788,6 +5788,13 @@
  2819. goto out;
  2820. }
  2821. +#ifdef CONFIG_PREEMPT_RT_FULL
  2822. + if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) {
  2823. + printk(KERN_ERR "RT requires X86_FEATURE_CONSTANT_TSC\n");
  2824. + return -EOPNOTSUPP;
  2825. + }
  2826. +#endif
  2827. +
  2828. r = kvm_mmu_module_init();
  2829. if (r)
  2830. goto out_free_percpu;
  2831. diff -Nur linux-4.4.13.orig/arch/x86/mm/highmem_32.c linux-4.4.13/arch/x86/mm/highmem_32.c
  2832. --- linux-4.4.13.orig/arch/x86/mm/highmem_32.c 2016-06-08 03:14:51.000000000 +0200
  2833. +++ linux-4.4.13/arch/x86/mm/highmem_32.c 2016-06-22 21:55:07.990523867 +0200
  2834. @@ -32,10 +32,11 @@
  2835. */
  2836. void *kmap_atomic_prot(struct page *page, pgprot_t prot)
  2837. {
  2838. + pte_t pte = mk_pte(page, prot);
  2839. unsigned long vaddr;
  2840. int idx, type;
  2841. - preempt_disable();
  2842. + preempt_disable_nort();
  2843. pagefault_disable();
  2844. if (!PageHighMem(page))
  2845. @@ -45,7 +46,10 @@
  2846. idx = type + KM_TYPE_NR*smp_processor_id();
  2847. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  2848. BUG_ON(!pte_none(*(kmap_pte-idx)));
  2849. - set_pte(kmap_pte-idx, mk_pte(page, prot));
  2850. +#ifdef CONFIG_PREEMPT_RT_FULL
  2851. + current->kmap_pte[type] = pte;
  2852. +#endif
  2853. + set_pte(kmap_pte-idx, pte);
  2854. arch_flush_lazy_mmu_mode();
  2855. return (void *)vaddr;
  2856. @@ -88,6 +92,9 @@
  2857. * is a bad idea also, in case the page changes cacheability
  2858. * attributes or becomes a protected page in a hypervisor.
  2859. */
  2860. +#ifdef CONFIG_PREEMPT_RT_FULL
  2861. + current->kmap_pte[type] = __pte(0);
  2862. +#endif
  2863. kpte_clear_flush(kmap_pte-idx, vaddr);
  2864. kmap_atomic_idx_pop();
  2865. arch_flush_lazy_mmu_mode();
  2866. @@ -100,7 +107,7 @@
  2867. #endif
  2868. pagefault_enable();
  2869. - preempt_enable();
  2870. + preempt_enable_nort();
  2871. }
  2872. EXPORT_SYMBOL(__kunmap_atomic);
  2873. diff -Nur linux-4.4.13.orig/arch/x86/mm/iomap_32.c linux-4.4.13/arch/x86/mm/iomap_32.c
  2874. --- linux-4.4.13.orig/arch/x86/mm/iomap_32.c 2016-06-08 03:14:51.000000000 +0200
  2875. +++ linux-4.4.13/arch/x86/mm/iomap_32.c 2016-06-22 21:55:07.990523867 +0200
  2876. @@ -56,6 +56,7 @@
  2877. void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
  2878. {
  2879. + pte_t pte = pfn_pte(pfn, prot);
  2880. unsigned long vaddr;
  2881. int idx, type;
  2882. @@ -65,7 +66,12 @@
  2883. type = kmap_atomic_idx_push();
  2884. idx = type + KM_TYPE_NR * smp_processor_id();
  2885. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  2886. - set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
  2887. + WARN_ON(!pte_none(*(kmap_pte - idx)));
  2888. +
  2889. +#ifdef CONFIG_PREEMPT_RT_FULL
  2890. + current->kmap_pte[type] = pte;
  2891. +#endif
  2892. + set_pte(kmap_pte - idx, pte);
  2893. arch_flush_lazy_mmu_mode();
  2894. return (void *)vaddr;
  2895. @@ -113,6 +119,9 @@
  2896. * is a bad idea also, in case the page changes cacheability
  2897. * attributes or becomes a protected page in a hypervisor.
  2898. */
  2899. +#ifdef CONFIG_PREEMPT_RT_FULL
  2900. + current->kmap_pte[type] = __pte(0);
  2901. +#endif
  2902. kpte_clear_flush(kmap_pte-idx, vaddr);
  2903. kmap_atomic_idx_pop();
  2904. }
  2905. diff -Nur linux-4.4.13.orig/arch/x86/platform/uv/tlb_uv.c linux-4.4.13/arch/x86/platform/uv/tlb_uv.c
  2906. --- linux-4.4.13.orig/arch/x86/platform/uv/tlb_uv.c 2016-06-08 03:14:51.000000000 +0200
  2907. +++ linux-4.4.13/arch/x86/platform/uv/tlb_uv.c 2016-06-22 21:55:07.990523867 +0200
  2908. @@ -714,9 +714,9 @@
  2909. quiesce_local_uvhub(hmaster);
  2910. - spin_lock(&hmaster->queue_lock);
  2911. + raw_spin_lock(&hmaster->queue_lock);
  2912. reset_with_ipi(&bau_desc->distribution, bcp);
  2913. - spin_unlock(&hmaster->queue_lock);
  2914. + raw_spin_unlock(&hmaster->queue_lock);
  2915. end_uvhub_quiesce(hmaster);
  2916. @@ -736,9 +736,9 @@
  2917. quiesce_local_uvhub(hmaster);
  2918. - spin_lock(&hmaster->queue_lock);
  2919. + raw_spin_lock(&hmaster->queue_lock);
  2920. reset_with_ipi(&bau_desc->distribution, bcp);
  2921. - spin_unlock(&hmaster->queue_lock);
  2922. + raw_spin_unlock(&hmaster->queue_lock);
  2923. end_uvhub_quiesce(hmaster);
  2924. @@ -759,7 +759,7 @@
  2925. cycles_t tm1;
  2926. hmaster = bcp->uvhub_master;
  2927. - spin_lock(&hmaster->disable_lock);
  2928. + raw_spin_lock(&hmaster->disable_lock);
  2929. if (!bcp->baudisabled) {
  2930. stat->s_bau_disabled++;
  2931. tm1 = get_cycles();
  2932. @@ -772,7 +772,7 @@
  2933. }
  2934. }
  2935. }
  2936. - spin_unlock(&hmaster->disable_lock);
  2937. + raw_spin_unlock(&hmaster->disable_lock);
  2938. }
  2939. static void count_max_concurr(int stat, struct bau_control *bcp,
  2940. @@ -835,7 +835,7 @@
  2941. */
  2942. static void uv1_throttle(struct bau_control *hmaster, struct ptc_stats *stat)
  2943. {
  2944. - spinlock_t *lock = &hmaster->uvhub_lock;
  2945. + raw_spinlock_t *lock = &hmaster->uvhub_lock;
  2946. atomic_t *v;
  2947. v = &hmaster->active_descriptor_count;
  2948. @@ -968,7 +968,7 @@
  2949. struct bau_control *hmaster;
  2950. hmaster = bcp->uvhub_master;
  2951. - spin_lock(&hmaster->disable_lock);
  2952. + raw_spin_lock(&hmaster->disable_lock);
  2953. if (bcp->baudisabled && (get_cycles() >= bcp->set_bau_on_time)) {
  2954. stat->s_bau_reenabled++;
  2955. for_each_present_cpu(tcpu) {
  2956. @@ -980,10 +980,10 @@
  2957. tbcp->period_giveups = 0;
  2958. }
  2959. }
  2960. - spin_unlock(&hmaster->disable_lock);
  2961. + raw_spin_unlock(&hmaster->disable_lock);
  2962. return 0;
  2963. }
  2964. - spin_unlock(&hmaster->disable_lock);
  2965. + raw_spin_unlock(&hmaster->disable_lock);
  2966. return -1;
  2967. }
  2968. @@ -1901,9 +1901,9 @@
  2969. bcp->cong_reps = congested_reps;
  2970. bcp->disabled_period = sec_2_cycles(disabled_period);
  2971. bcp->giveup_limit = giveup_limit;
  2972. - spin_lock_init(&bcp->queue_lock);
  2973. - spin_lock_init(&bcp->uvhub_lock);
  2974. - spin_lock_init(&bcp->disable_lock);
  2975. + raw_spin_lock_init(&bcp->queue_lock);
  2976. + raw_spin_lock_init(&bcp->uvhub_lock);
  2977. + raw_spin_lock_init(&bcp->disable_lock);
  2978. }
  2979. }
  2980. diff -Nur linux-4.4.13.orig/arch/x86/platform/uv/uv_time.c linux-4.4.13/arch/x86/platform/uv/uv_time.c
  2981. --- linux-4.4.13.orig/arch/x86/platform/uv/uv_time.c 2016-06-08 03:14:51.000000000 +0200
  2982. +++ linux-4.4.13/arch/x86/platform/uv/uv_time.c 2016-06-22 21:55:07.990523867 +0200
  2983. @@ -57,7 +57,7 @@
  2984. /* There is one of these allocated per node */
  2985. struct uv_rtc_timer_head {
  2986. - spinlock_t lock;
  2987. + raw_spinlock_t lock;
  2988. /* next cpu waiting for timer, local node relative: */
  2989. int next_cpu;
  2990. /* number of cpus on this node: */
  2991. @@ -177,7 +177,7 @@
  2992. uv_rtc_deallocate_timers();
  2993. return -ENOMEM;
  2994. }
  2995. - spin_lock_init(&head->lock);
  2996. + raw_spin_lock_init(&head->lock);
  2997. head->ncpus = uv_blade_nr_possible_cpus(bid);
  2998. head->next_cpu = -1;
  2999. blade_info[bid] = head;
  3000. @@ -231,7 +231,7 @@
  3001. unsigned long flags;
  3002. int next_cpu;
  3003. - spin_lock_irqsave(&head->lock, flags);
  3004. + raw_spin_lock_irqsave(&head->lock, flags);
  3005. next_cpu = head->next_cpu;
  3006. *t = expires;
  3007. @@ -243,12 +243,12 @@
  3008. if (uv_setup_intr(cpu, expires)) {
  3009. *t = ULLONG_MAX;
  3010. uv_rtc_find_next_timer(head, pnode);
  3011. - spin_unlock_irqrestore(&head->lock, flags);
  3012. + raw_spin_unlock_irqrestore(&head->lock, flags);
  3013. return -ETIME;
  3014. }
  3015. }
  3016. - spin_unlock_irqrestore(&head->lock, flags);
  3017. + raw_spin_unlock_irqrestore(&head->lock, flags);
  3018. return 0;
  3019. }
  3020. @@ -267,7 +267,7 @@
  3021. unsigned long flags;
  3022. int rc = 0;
  3023. - spin_lock_irqsave(&head->lock, flags);
  3024. + raw_spin_lock_irqsave(&head->lock, flags);
  3025. if ((head->next_cpu == bcpu && uv_read_rtc(NULL) >= *t) || force)
  3026. rc = 1;
  3027. @@ -279,7 +279,7 @@
  3028. uv_rtc_find_next_timer(head, pnode);
  3029. }
  3030. - spin_unlock_irqrestore(&head->lock, flags);
  3031. + raw_spin_unlock_irqrestore(&head->lock, flags);
  3032. return rc;
  3033. }
  3034. @@ -299,13 +299,18 @@
  3035. static cycle_t uv_read_rtc(struct clocksource *cs)
  3036. {
  3037. unsigned long offset;
  3038. + cycle_t cycles;
  3039. + preempt_disable();
  3040. if (uv_get_min_hub_revision_id() == 1)
  3041. offset = 0;
  3042. else
  3043. offset = (uv_blade_processor_id() * L1_CACHE_BYTES) % PAGE_SIZE;
  3044. - return (cycle_t)uv_read_local_mmr(UVH_RTC | offset);
  3045. + cycles = (cycle_t)uv_read_local_mmr(UVH_RTC | offset);
  3046. + preempt_enable();
  3047. +
  3048. + return cycles;
  3049. }
  3050. /*
  3051. diff -Nur linux-4.4.13.orig/block/blk-core.c linux-4.4.13/block/blk-core.c
  3052. --- linux-4.4.13.orig/block/blk-core.c 2016-06-08 03:14:51.000000000 +0200
  3053. +++ linux-4.4.13/block/blk-core.c 2016-06-22 21:55:07.990523867 +0200
  3054. @@ -125,6 +125,9 @@
  3055. INIT_LIST_HEAD(&rq->queuelist);
  3056. INIT_LIST_HEAD(&rq->timeout_list);
  3057. +#ifdef CONFIG_PREEMPT_RT_FULL
  3058. + INIT_WORK(&rq->work, __blk_mq_complete_request_remote_work);
  3059. +#endif
  3060. rq->cpu = -1;
  3061. rq->q = q;
  3062. rq->__sector = (sector_t) -1;
  3063. @@ -233,7 +236,7 @@
  3064. **/
  3065. void blk_start_queue(struct request_queue *q)
  3066. {
  3067. - WARN_ON(!irqs_disabled());
  3068. + WARN_ON_NONRT(!irqs_disabled());
  3069. queue_flag_clear(QUEUE_FLAG_STOPPED, q);
  3070. __blk_run_queue(q);
  3071. @@ -657,7 +660,7 @@
  3072. if (!gfpflags_allow_blocking(gfp))
  3073. return -EBUSY;
  3074. - ret = wait_event_interruptible(q->mq_freeze_wq,
  3075. + ret = swait_event_interruptible(q->mq_freeze_wq,
  3076. !atomic_read(&q->mq_freeze_depth) ||
  3077. blk_queue_dying(q));
  3078. if (blk_queue_dying(q))
  3079. @@ -677,7 +680,7 @@
  3080. struct request_queue *q =
  3081. container_of(ref, struct request_queue, q_usage_counter);
  3082. - wake_up_all(&q->mq_freeze_wq);
  3083. + swake_up_all(&q->mq_freeze_wq);
  3084. }
  3085. struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
  3086. @@ -739,7 +742,7 @@
  3087. q->bypass_depth = 1;
  3088. __set_bit(QUEUE_FLAG_BYPASS, &q->queue_flags);
  3089. - init_waitqueue_head(&q->mq_freeze_wq);
  3090. + init_swait_queue_head(&q->mq_freeze_wq);
  3091. /*
  3092. * Init percpu_ref in atomic mode so that it's faster to shutdown.
  3093. @@ -3198,7 +3201,7 @@
  3094. blk_run_queue_async(q);
  3095. else
  3096. __blk_run_queue(q);
  3097. - spin_unlock(q->queue_lock);
  3098. + spin_unlock_irq(q->queue_lock);
  3099. }
  3100. static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule)
  3101. @@ -3246,7 +3249,6 @@
  3102. void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
  3103. {
  3104. struct request_queue *q;
  3105. - unsigned long flags;
  3106. struct request *rq;
  3107. LIST_HEAD(list);
  3108. unsigned int depth;
  3109. @@ -3266,11 +3268,6 @@
  3110. q = NULL;
  3111. depth = 0;
  3112. - /*
  3113. - * Save and disable interrupts here, to avoid doing it for every
  3114. - * queue lock we have to take.
  3115. - */
  3116. - local_irq_save(flags);
  3117. while (!list_empty(&list)) {
  3118. rq = list_entry_rq(list.next);
  3119. list_del_init(&rq->queuelist);
  3120. @@ -3283,7 +3280,7 @@
  3121. queue_unplugged(q, depth, from_schedule);
  3122. q = rq->q;
  3123. depth = 0;
  3124. - spin_lock(q->queue_lock);
  3125. + spin_lock_irq(q->queue_lock);
  3126. }
  3127. /*
  3128. @@ -3310,8 +3307,6 @@
  3129. */
  3130. if (q)
  3131. queue_unplugged(q, depth, from_schedule);
  3132. -
  3133. - local_irq_restore(flags);
  3134. }
  3135. void blk_finish_plug(struct blk_plug *plug)
  3136. diff -Nur linux-4.4.13.orig/block/blk-ioc.c linux-4.4.13/block/blk-ioc.c
  3137. --- linux-4.4.13.orig/block/blk-ioc.c 2016-06-08 03:14:51.000000000 +0200
  3138. +++ linux-4.4.13/block/blk-ioc.c 2016-06-22 21:55:07.990523867 +0200
  3139. @@ -7,6 +7,7 @@
  3140. #include <linux/bio.h>
  3141. #include <linux/blkdev.h>
  3142. #include <linux/slab.h>
  3143. +#include <linux/delay.h>
  3144. #include "blk.h"
  3145. @@ -109,7 +110,7 @@
  3146. spin_unlock(q->queue_lock);
  3147. } else {
  3148. spin_unlock_irqrestore(&ioc->lock, flags);
  3149. - cpu_relax();
  3150. + cpu_chill();
  3151. spin_lock_irqsave_nested(&ioc->lock, flags, 1);
  3152. }
  3153. }
  3154. @@ -187,7 +188,7 @@
  3155. spin_unlock(icq->q->queue_lock);
  3156. } else {
  3157. spin_unlock_irqrestore(&ioc->lock, flags);
  3158. - cpu_relax();
  3159. + cpu_chill();
  3160. goto retry;
  3161. }
  3162. }
  3163. diff -Nur linux-4.4.13.orig/block/blk-iopoll.c linux-4.4.13/block/blk-iopoll.c
  3164. --- linux-4.4.13.orig/block/blk-iopoll.c 2016-06-08 03:14:51.000000000 +0200
  3165. +++ linux-4.4.13/block/blk-iopoll.c 2016-06-22 21:55:07.990523867 +0200
  3166. @@ -35,6 +35,7 @@
  3167. list_add_tail(&iop->list, this_cpu_ptr(&blk_cpu_iopoll));
  3168. __raise_softirq_irqoff(BLOCK_IOPOLL_SOFTIRQ);
  3169. local_irq_restore(flags);
  3170. + preempt_check_resched_rt();
  3171. }
  3172. EXPORT_SYMBOL(blk_iopoll_sched);
  3173. @@ -132,6 +133,7 @@
  3174. __raise_softirq_irqoff(BLOCK_IOPOLL_SOFTIRQ);
  3175. local_irq_enable();
  3176. + preempt_check_resched_rt();
  3177. }
  3178. /**
  3179. @@ -201,6 +203,7 @@
  3180. this_cpu_ptr(&blk_cpu_iopoll));
  3181. __raise_softirq_irqoff(BLOCK_IOPOLL_SOFTIRQ);
  3182. local_irq_enable();
  3183. + preempt_check_resched_rt();
  3184. }
  3185. return NOTIFY_OK;
  3186. diff -Nur linux-4.4.13.orig/block/blk-mq.c linux-4.4.13/block/blk-mq.c
  3187. --- linux-4.4.13.orig/block/blk-mq.c 2016-06-08 03:14:51.000000000 +0200
  3188. +++ linux-4.4.13/block/blk-mq.c 2016-06-22 21:55:07.990523867 +0200
  3189. @@ -92,7 +92,7 @@
  3190. static void blk_mq_freeze_queue_wait(struct request_queue *q)
  3191. {
  3192. - wait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->q_usage_counter));
  3193. + swait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->q_usage_counter));
  3194. }
  3195. /*
  3196. @@ -130,7 +130,7 @@
  3197. WARN_ON_ONCE(freeze_depth < 0);
  3198. if (!freeze_depth) {
  3199. percpu_ref_reinit(&q->q_usage_counter);
  3200. - wake_up_all(&q->mq_freeze_wq);
  3201. + swake_up_all(&q->mq_freeze_wq);
  3202. }
  3203. }
  3204. EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue);
  3205. @@ -149,7 +149,7 @@
  3206. * dying, we need to ensure that processes currently waiting on
  3207. * the queue are notified as well.
  3208. */
  3209. - wake_up_all(&q->mq_freeze_wq);
  3210. + swake_up_all(&q->mq_freeze_wq);
  3211. }
  3212. bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx)
  3213. @@ -196,6 +196,9 @@
  3214. rq->resid_len = 0;
  3215. rq->sense = NULL;
  3216. +#ifdef CONFIG_PREEMPT_RT_FULL
  3217. + INIT_WORK(&rq->work, __blk_mq_complete_request_remote_work);
  3218. +#endif
  3219. INIT_LIST_HEAD(&rq->timeout_list);
  3220. rq->timeout = 0;
  3221. @@ -325,6 +328,17 @@
  3222. }
  3223. EXPORT_SYMBOL(blk_mq_end_request);
  3224. +#ifdef CONFIG_PREEMPT_RT_FULL
  3225. +
  3226. +void __blk_mq_complete_request_remote_work(struct work_struct *work)
  3227. +{
  3228. + struct request *rq = container_of(work, struct request, work);
  3229. +
  3230. + rq->q->softirq_done_fn(rq);
  3231. +}
  3232. +
  3233. +#else
  3234. +
  3235. static void __blk_mq_complete_request_remote(void *data)
  3236. {
  3237. struct request *rq = data;
  3238. @@ -332,6 +346,8 @@
  3239. rq->q->softirq_done_fn(rq);
  3240. }
  3241. +#endif
  3242. +
  3243. static void blk_mq_ipi_complete_request(struct request *rq)
  3244. {
  3245. struct blk_mq_ctx *ctx = rq->mq_ctx;
  3246. @@ -343,19 +359,23 @@
  3247. return;
  3248. }
  3249. - cpu = get_cpu();
  3250. + cpu = get_cpu_light();
  3251. if (!test_bit(QUEUE_FLAG_SAME_FORCE, &rq->q->queue_flags))
  3252. shared = cpus_share_cache(cpu, ctx->cpu);
  3253. if (cpu != ctx->cpu && !shared && cpu_online(ctx->cpu)) {
  3254. +#ifdef CONFIG_PREEMPT_RT_FULL
  3255. + schedule_work_on(ctx->cpu, &rq->work);
  3256. +#else
  3257. rq->csd.func = __blk_mq_complete_request_remote;
  3258. rq->csd.info = rq;
  3259. rq->csd.flags = 0;
  3260. smp_call_function_single_async(ctx->cpu, &rq->csd);
  3261. +#endif
  3262. } else {
  3263. rq->q->softirq_done_fn(rq);
  3264. }
  3265. - put_cpu();
  3266. + put_cpu_light();
  3267. }
  3268. static void __blk_mq_complete_request(struct request *rq)
  3269. @@ -862,14 +882,14 @@
  3270. return;
  3271. if (!async) {
  3272. - int cpu = get_cpu();
  3273. + int cpu = get_cpu_light();
  3274. if (cpumask_test_cpu(cpu, hctx->cpumask)) {
  3275. __blk_mq_run_hw_queue(hctx);
  3276. - put_cpu();
  3277. + put_cpu_light();
  3278. return;
  3279. }
  3280. - put_cpu();
  3281. + put_cpu_light();
  3282. }
  3283. kblockd_schedule_delayed_work_on(blk_mq_hctx_next_cpu(hctx),
  3284. @@ -1617,7 +1637,7 @@
  3285. {
  3286. struct blk_mq_hw_ctx *hctx = data;
  3287. - if (action == CPU_DEAD || action == CPU_DEAD_FROZEN)
  3288. + if (action == CPU_POST_DEAD)
  3289. return blk_mq_hctx_cpu_offline(hctx, cpu);
  3290. /*
  3291. diff -Nur linux-4.4.13.orig/block/blk-mq-cpu.c linux-4.4.13/block/blk-mq-cpu.c
  3292. --- linux-4.4.13.orig/block/blk-mq-cpu.c 2016-06-08 03:14:51.000000000 +0200
  3293. +++ linux-4.4.13/block/blk-mq-cpu.c 2016-06-22 21:55:07.990523867 +0200
  3294. @@ -16,7 +16,7 @@
  3295. #include "blk-mq.h"
  3296. static LIST_HEAD(blk_mq_cpu_notify_list);
  3297. -static DEFINE_RAW_SPINLOCK(blk_mq_cpu_notify_lock);
  3298. +static DEFINE_SPINLOCK(blk_mq_cpu_notify_lock);
  3299. static int blk_mq_main_cpu_notify(struct notifier_block *self,
  3300. unsigned long action, void *hcpu)
  3301. @@ -25,7 +25,10 @@
  3302. struct blk_mq_cpu_notifier *notify;
  3303. int ret = NOTIFY_OK;
  3304. - raw_spin_lock(&blk_mq_cpu_notify_lock);
  3305. + if (action != CPU_POST_DEAD)
  3306. + return NOTIFY_OK;
  3307. +
  3308. + spin_lock(&blk_mq_cpu_notify_lock);
  3309. list_for_each_entry(notify, &blk_mq_cpu_notify_list, list) {
  3310. ret = notify->notify(notify->data, action, cpu);
  3311. @@ -33,7 +36,7 @@
  3312. break;
  3313. }
  3314. - raw_spin_unlock(&blk_mq_cpu_notify_lock);
  3315. + spin_unlock(&blk_mq_cpu_notify_lock);
  3316. return ret;
  3317. }
  3318. @@ -41,16 +44,16 @@
  3319. {
  3320. BUG_ON(!notifier->notify);
  3321. - raw_spin_lock(&blk_mq_cpu_notify_lock);
  3322. + spin_lock(&blk_mq_cpu_notify_lock);
  3323. list_add_tail(&notifier->list, &blk_mq_cpu_notify_list);
  3324. - raw_spin_unlock(&blk_mq_cpu_notify_lock);
  3325. + spin_unlock(&blk_mq_cpu_notify_lock);
  3326. }
  3327. void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier *notifier)
  3328. {
  3329. - raw_spin_lock(&blk_mq_cpu_notify_lock);
  3330. + spin_lock(&blk_mq_cpu_notify_lock);
  3331. list_del(&notifier->list);
  3332. - raw_spin_unlock(&blk_mq_cpu_notify_lock);
  3333. + spin_unlock(&blk_mq_cpu_notify_lock);
  3334. }
  3335. void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier *notifier,
  3336. diff -Nur linux-4.4.13.orig/block/blk-mq.h linux-4.4.13/block/blk-mq.h
  3337. --- linux-4.4.13.orig/block/blk-mq.h 2016-06-08 03:14:51.000000000 +0200
  3338. +++ linux-4.4.13/block/blk-mq.h 2016-06-22 21:55:07.990523867 +0200
  3339. @@ -74,7 +74,10 @@
  3340. static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q,
  3341. unsigned int cpu)
  3342. {
  3343. - return per_cpu_ptr(q->queue_ctx, cpu);
  3344. + struct blk_mq_ctx *ctx;
  3345. +
  3346. + ctx = per_cpu_ptr(q->queue_ctx, cpu);
  3347. + return ctx;
  3348. }
  3349. /*
  3350. @@ -85,12 +88,12 @@
  3351. */
  3352. static inline struct blk_mq_ctx *blk_mq_get_ctx(struct request_queue *q)
  3353. {
  3354. - return __blk_mq_get_ctx(q, get_cpu());
  3355. + return __blk_mq_get_ctx(q, get_cpu_light());
  3356. }
  3357. static inline void blk_mq_put_ctx(struct blk_mq_ctx *ctx)
  3358. {
  3359. - put_cpu();
  3360. + put_cpu_light();
  3361. }
  3362. struct blk_mq_alloc_data {
  3363. diff -Nur linux-4.4.13.orig/block/blk-softirq.c linux-4.4.13/block/blk-softirq.c
  3364. --- linux-4.4.13.orig/block/blk-softirq.c 2016-06-08 03:14:51.000000000 +0200
  3365. +++ linux-4.4.13/block/blk-softirq.c 2016-06-22 21:55:07.990523867 +0200
  3366. @@ -51,6 +51,7 @@
  3367. raise_softirq_irqoff(BLOCK_SOFTIRQ);
  3368. local_irq_restore(flags);
  3369. + preempt_check_resched_rt();
  3370. }
  3371. /*
  3372. @@ -93,6 +94,7 @@
  3373. this_cpu_ptr(&blk_cpu_done));
  3374. raise_softirq_irqoff(BLOCK_SOFTIRQ);
  3375. local_irq_enable();
  3376. + preempt_check_resched_rt();
  3377. }
  3378. return NOTIFY_OK;
  3379. @@ -150,6 +152,7 @@
  3380. goto do_local;
  3381. local_irq_restore(flags);
  3382. + preempt_check_resched_rt();
  3383. }
  3384. /**
  3385. diff -Nur linux-4.4.13.orig/block/bounce.c linux-4.4.13/block/bounce.c
  3386. --- linux-4.4.13.orig/block/bounce.c 2016-06-08 03:14:51.000000000 +0200
  3387. +++ linux-4.4.13/block/bounce.c 2016-06-22 21:55:07.990523867 +0200
  3388. @@ -55,11 +55,11 @@
  3389. unsigned long flags;
  3390. unsigned char *vto;
  3391. - local_irq_save(flags);
  3392. + local_irq_save_nort(flags);
  3393. vto = kmap_atomic(to->bv_page);
  3394. memcpy(vto + to->bv_offset, vfrom, to->bv_len);
  3395. kunmap_atomic(vto);
  3396. - local_irq_restore(flags);
  3397. + local_irq_restore_nort(flags);
  3398. }
  3399. #else /* CONFIG_HIGHMEM */
  3400. diff -Nur linux-4.4.13.orig/crypto/algapi.c linux-4.4.13/crypto/algapi.c
  3401. --- linux-4.4.13.orig/crypto/algapi.c 2016-06-08 03:14:51.000000000 +0200
  3402. +++ linux-4.4.13/crypto/algapi.c 2016-06-22 21:55:07.990523867 +0200
  3403. @@ -719,13 +719,13 @@
  3404. int crypto_register_notifier(struct notifier_block *nb)
  3405. {
  3406. - return blocking_notifier_chain_register(&crypto_chain, nb);
  3407. + return srcu_notifier_chain_register(&crypto_chain, nb);
  3408. }
  3409. EXPORT_SYMBOL_GPL(crypto_register_notifier);
  3410. int crypto_unregister_notifier(struct notifier_block *nb)
  3411. {
  3412. - return blocking_notifier_chain_unregister(&crypto_chain, nb);
  3413. + return srcu_notifier_chain_unregister(&crypto_chain, nb);
  3414. }
  3415. EXPORT_SYMBOL_GPL(crypto_unregister_notifier);
  3416. diff -Nur linux-4.4.13.orig/crypto/api.c linux-4.4.13/crypto/api.c
  3417. --- linux-4.4.13.orig/crypto/api.c 2016-06-08 03:14:51.000000000 +0200
  3418. +++ linux-4.4.13/crypto/api.c 2016-06-22 21:55:07.990523867 +0200
  3419. @@ -31,7 +31,7 @@
  3420. DECLARE_RWSEM(crypto_alg_sem);
  3421. EXPORT_SYMBOL_GPL(crypto_alg_sem);
  3422. -BLOCKING_NOTIFIER_HEAD(crypto_chain);
  3423. +SRCU_NOTIFIER_HEAD(crypto_chain);
  3424. EXPORT_SYMBOL_GPL(crypto_chain);
  3425. static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
  3426. @@ -236,10 +236,10 @@
  3427. {
  3428. int ok;
  3429. - ok = blocking_notifier_call_chain(&crypto_chain, val, v);
  3430. + ok = srcu_notifier_call_chain(&crypto_chain, val, v);
  3431. if (ok == NOTIFY_DONE) {
  3432. request_module("cryptomgr");
  3433. - ok = blocking_notifier_call_chain(&crypto_chain, val, v);
  3434. + ok = srcu_notifier_call_chain(&crypto_chain, val, v);
  3435. }
  3436. return ok;
  3437. diff -Nur linux-4.4.13.orig/crypto/internal.h linux-4.4.13/crypto/internal.h
  3438. --- linux-4.4.13.orig/crypto/internal.h 2016-06-08 03:14:51.000000000 +0200
  3439. +++ linux-4.4.13/crypto/internal.h 2016-06-22 21:55:07.990523867 +0200
  3440. @@ -47,7 +47,7 @@
  3441. extern struct list_head crypto_alg_list;
  3442. extern struct rw_semaphore crypto_alg_sem;
  3443. -extern struct blocking_notifier_head crypto_chain;
  3444. +extern struct srcu_notifier_head crypto_chain;
  3445. #ifdef CONFIG_PROC_FS
  3446. void __init crypto_init_proc(void);
  3447. @@ -143,7 +143,7 @@
  3448. static inline void crypto_notify(unsigned long val, void *v)
  3449. {
  3450. - blocking_notifier_call_chain(&crypto_chain, val, v);
  3451. + srcu_notifier_call_chain(&crypto_chain, val, v);
  3452. }
  3453. #endif /* _CRYPTO_INTERNAL_H */
  3454. diff -Nur linux-4.4.13.orig/Documentation/hwlat_detector.txt linux-4.4.13/Documentation/hwlat_detector.txt
  3455. --- linux-4.4.13.orig/Documentation/hwlat_detector.txt 1970-01-01 01:00:00.000000000 +0100
  3456. +++ linux-4.4.13/Documentation/hwlat_detector.txt 2016-06-22 21:55:07.994523867 +0200
  3457. @@ -0,0 +1,64 @@
  3458. +Introduction:
  3459. +-------------
  3460. +
  3461. +The module hwlat_detector is a special purpose kernel module that is used to
  3462. +detect large system latencies induced by the behavior of certain underlying
  3463. +hardware or firmware, independent of Linux itself. The code was developed
  3464. +originally to detect SMIs (System Management Interrupts) on x86 systems,
  3465. +however there is nothing x86 specific about this patchset. It was
  3466. +originally written for use by the "RT" patch since the Real Time
  3467. +kernel is highly latency sensitive.
  3468. +
  3469. +SMIs are usually not serviced by the Linux kernel, which typically does not
  3470. +even know that they are occuring. SMIs are instead are set up by BIOS code
  3471. +and are serviced by BIOS code, usually for "critical" events such as
  3472. +management of thermal sensors and fans. Sometimes though, SMIs are used for
  3473. +other tasks and those tasks can spend an inordinate amount of time in the
  3474. +handler (sometimes measured in milliseconds). Obviously this is a problem if
  3475. +you are trying to keep event service latencies down in the microsecond range.
  3476. +
  3477. +The hardware latency detector works by hogging all of the cpus for configurable
  3478. +amounts of time (by calling stop_machine()), polling the CPU Time Stamp Counter
  3479. +for some period, then looking for gaps in the TSC data. Any gap indicates a
  3480. +time when the polling was interrupted and since the machine is stopped and
  3481. +interrupts turned off the only thing that could do that would be an SMI.
  3482. +
  3483. +Note that the SMI detector should *NEVER* be used in a production environment.
  3484. +It is intended to be run manually to determine if the hardware platform has a
  3485. +problem with long system firmware service routines.
  3486. +
  3487. +Usage:
  3488. +------
  3489. +
  3490. +Loading the module hwlat_detector passing the parameter "enabled=1" (or by
  3491. +setting the "enable" entry in "hwlat_detector" debugfs toggled on) is the only
  3492. +step required to start the hwlat_detector. It is possible to redefine the
  3493. +threshold in microseconds (us) above which latency spikes will be taken
  3494. +into account (parameter "threshold=").
  3495. +
  3496. +Example:
  3497. +
  3498. + # modprobe hwlat_detector enabled=1 threshold=100
  3499. +
  3500. +After the module is loaded, it creates a directory named "hwlat_detector" under
  3501. +the debugfs mountpoint, "/debug/hwlat_detector" for this text. It is necessary
  3502. +to have debugfs mounted, which might be on /sys/debug on your system.
  3503. +
  3504. +The /debug/hwlat_detector interface contains the following files:
  3505. +
  3506. +count - number of latency spikes observed since last reset
  3507. +enable - a global enable/disable toggle (0/1), resets count
  3508. +max - maximum hardware latency actually observed (usecs)
  3509. +sample - a pipe from which to read current raw sample data
  3510. + in the format <timestamp> <latency observed usecs>
  3511. + (can be opened O_NONBLOCK for a single sample)
  3512. +threshold - minimum latency value to be considered (usecs)
  3513. +width - time period to sample with CPUs held (usecs)
  3514. + must be less than the total window size (enforced)
  3515. +window - total period of sampling, width being inside (usecs)
  3516. +
  3517. +By default we will set width to 500,000 and window to 1,000,000, meaning that
  3518. +we will sample every 1,000,000 usecs (1s) for 500,000 usecs (0.5s). If we
  3519. +observe any latencies that exceed the threshold (initially 100 usecs),
  3520. +then we write to a global sample ring buffer of 8K samples, which is
  3521. +consumed by reading from the "sample" (pipe) debugfs file interface.
  3522. diff -Nur linux-4.4.13.orig/Documentation/kernel-parameters.txt linux-4.4.13/Documentation/kernel-parameters.txt
  3523. --- linux-4.4.13.orig/Documentation/kernel-parameters.txt 2016-06-08 03:14:51.000000000 +0200
  3524. +++ linux-4.4.13/Documentation/kernel-parameters.txt 2016-06-22 21:55:07.994523867 +0200
  3525. @@ -1629,6 +1629,15 @@
  3526. ip= [IP_PNP]
  3527. See Documentation/filesystems/nfs/nfsroot.txt.
  3528. + irqaffinity= [SMP] Set the default irq affinity mask
  3529. + Format:
  3530. + <cpu number>,...,<cpu number>
  3531. + or
  3532. + <cpu number>-<cpu number>
  3533. + (must be a positive range in ascending order)
  3534. + or a mixture
  3535. + <cpu number>,...,<cpu number>-<cpu number>
  3536. +
  3537. irqfixup [HW]
  3538. When an interrupt is not handled search all handlers
  3539. for it. Intended to get systems with badly broken
  3540. diff -Nur linux-4.4.13.orig/Documentation/sysrq.txt linux-4.4.13/Documentation/sysrq.txt
  3541. --- linux-4.4.13.orig/Documentation/sysrq.txt 2016-06-08 03:14:51.000000000 +0200
  3542. +++ linux-4.4.13/Documentation/sysrq.txt 2016-06-22 21:55:07.994523867 +0200
  3543. @@ -59,10 +59,17 @@
  3544. On other - If you know of the key combos for other architectures, please
  3545. let me know so I can add them to this section.
  3546. -On all - write a character to /proc/sysrq-trigger. e.g.:
  3547. -
  3548. +On all - write a character to /proc/sysrq-trigger, e.g.:
  3549. echo t > /proc/sysrq-trigger
  3550. +On all - Enable network SysRq by writing a cookie to icmp_echo_sysrq, e.g.
  3551. + echo 0x01020304 >/proc/sys/net/ipv4/icmp_echo_sysrq
  3552. + Send an ICMP echo request with this pattern plus the particular
  3553. + SysRq command key. Example:
  3554. + # ping -c1 -s57 -p0102030468
  3555. + will trigger the SysRq-H (help) command.
  3556. +
  3557. +
  3558. * What are the 'command' keys?
  3559. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3560. 'b' - Will immediately reboot the system without syncing or unmounting
  3561. diff -Nur linux-4.4.13.orig/Documentation/trace/histograms.txt linux-4.4.13/Documentation/trace/histograms.txt
  3562. --- linux-4.4.13.orig/Documentation/trace/histograms.txt 1970-01-01 01:00:00.000000000 +0100
  3563. +++ linux-4.4.13/Documentation/trace/histograms.txt 2016-06-22 21:55:07.994523867 +0200
  3564. @@ -0,0 +1,186 @@
  3565. + Using the Linux Kernel Latency Histograms
  3566. +
  3567. +
  3568. +This document gives a short explanation how to enable, configure and use
  3569. +latency histograms. Latency histograms are primarily relevant in the
  3570. +context of real-time enabled kernels (CONFIG_PREEMPT/CONFIG_PREEMPT_RT)
  3571. +and are used in the quality management of the Linux real-time
  3572. +capabilities.
  3573. +
  3574. +
  3575. +* Purpose of latency histograms
  3576. +
  3577. +A latency histogram continuously accumulates the frequencies of latency
  3578. +data. There are two types of histograms
  3579. +- potential sources of latencies
  3580. +- effective latencies
  3581. +
  3582. +
  3583. +* Potential sources of latencies
  3584. +
  3585. +Potential sources of latencies are code segments where interrupts,
  3586. +preemption or both are disabled (aka critical sections). To create
  3587. +histograms of potential sources of latency, the kernel stores the time
  3588. +stamp at the start of a critical section, determines the time elapsed
  3589. +when the end of the section is reached, and increments the frequency
  3590. +counter of that latency value - irrespective of whether any concurrently
  3591. +running process is affected by latency or not.
  3592. +- Configuration items (in the Kernel hacking/Tracers submenu)
  3593. + CONFIG_INTERRUPT_OFF_LATENCY
  3594. + CONFIG_PREEMPT_OFF_LATENCY
  3595. +
  3596. +
  3597. +* Effective latencies
  3598. +
  3599. +Effective latencies are actually occuring during wakeup of a process. To
  3600. +determine effective latencies, the kernel stores the time stamp when a
  3601. +process is scheduled to be woken up, and determines the duration of the
  3602. +wakeup time shortly before control is passed over to this process. Note
  3603. +that the apparent latency in user space may be somewhat longer, since the
  3604. +process may be interrupted after control is passed over to it but before
  3605. +the execution in user space takes place. Simply measuring the interval
  3606. +between enqueuing and wakeup may also not appropriate in cases when a
  3607. +process is scheduled as a result of a timer expiration. The timer may have
  3608. +missed its deadline, e.g. due to disabled interrupts, but this latency
  3609. +would not be registered. Therefore, the offsets of missed timers are
  3610. +recorded in a separate histogram. If both wakeup latency and missed timer
  3611. +offsets are configured and enabled, a third histogram may be enabled that
  3612. +records the overall latency as a sum of the timer latency, if any, and the
  3613. +wakeup latency. This histogram is called "timerandwakeup".
  3614. +- Configuration items (in the Kernel hacking/Tracers submenu)
  3615. + CONFIG_WAKEUP_LATENCY
  3616. + CONFIG_MISSED_TIMER_OFSETS
  3617. +
  3618. +
  3619. +* Usage
  3620. +
  3621. +The interface to the administration of the latency histograms is located
  3622. +in the debugfs file system. To mount it, either enter
  3623. +
  3624. +mount -t sysfs nodev /sys
  3625. +mount -t debugfs nodev /sys/kernel/debug
  3626. +
  3627. +from shell command line level, or add
  3628. +
  3629. +nodev /sys sysfs defaults 0 0
  3630. +nodev /sys/kernel/debug debugfs defaults 0 0
  3631. +
  3632. +to the file /etc/fstab. All latency histogram related files are then
  3633. +available in the directory /sys/kernel/debug/tracing/latency_hist. A
  3634. +particular histogram type is enabled by writing non-zero to the related
  3635. +variable in the /sys/kernel/debug/tracing/latency_hist/enable directory.
  3636. +Select "preemptirqsoff" for the histograms of potential sources of
  3637. +latencies and "wakeup" for histograms of effective latencies etc. The
  3638. +histogram data - one per CPU - are available in the files
  3639. +
  3640. +/sys/kernel/debug/tracing/latency_hist/preemptoff/CPUx
  3641. +/sys/kernel/debug/tracing/latency_hist/irqsoff/CPUx
  3642. +/sys/kernel/debug/tracing/latency_hist/preemptirqsoff/CPUx
  3643. +/sys/kernel/debug/tracing/latency_hist/wakeup/CPUx
  3644. +/sys/kernel/debug/tracing/latency_hist/wakeup/sharedprio/CPUx
  3645. +/sys/kernel/debug/tracing/latency_hist/missed_timer_offsets/CPUx
  3646. +/sys/kernel/debug/tracing/latency_hist/timerandwakeup/CPUx
  3647. +
  3648. +The histograms are reset by writing non-zero to the file "reset" in a
  3649. +particular latency directory. To reset all latency data, use
  3650. +
  3651. +#!/bin/sh
  3652. +
  3653. +TRACINGDIR=/sys/kernel/debug/tracing
  3654. +HISTDIR=$TRACINGDIR/latency_hist
  3655. +
  3656. +if test -d $HISTDIR
  3657. +then
  3658. + cd $HISTDIR
  3659. + for i in `find . | grep /reset$`
  3660. + do
  3661. + echo 1 >$i
  3662. + done
  3663. +fi
  3664. +
  3665. +
  3666. +* Data format
  3667. +
  3668. +Latency data are stored with a resolution of one microsecond. The
  3669. +maximum latency is 10,240 microseconds. The data are only valid, if the
  3670. +overflow register is empty. Every output line contains the latency in
  3671. +microseconds in the first row and the number of samples in the second
  3672. +row. To display only lines with a positive latency count, use, for
  3673. +example,
  3674. +
  3675. +grep -v " 0$" /sys/kernel/debug/tracing/latency_hist/preemptoff/CPU0
  3676. +
  3677. +#Minimum latency: 0 microseconds.
  3678. +#Average latency: 0 microseconds.
  3679. +#Maximum latency: 25 microseconds.
  3680. +#Total samples: 3104770694
  3681. +#There are 0 samples greater or equal than 10240 microseconds
  3682. +#usecs samples
  3683. + 0 2984486876
  3684. + 1 49843506
  3685. + 2 58219047
  3686. + 3 5348126
  3687. + 4 2187960
  3688. + 5 3388262
  3689. + 6 959289
  3690. + 7 208294
  3691. + 8 40420
  3692. + 9 4485
  3693. + 10 14918
  3694. + 11 18340
  3695. + 12 25052
  3696. + 13 19455
  3697. + 14 5602
  3698. + 15 969
  3699. + 16 47
  3700. + 17 18
  3701. + 18 14
  3702. + 19 1
  3703. + 20 3
  3704. + 21 2
  3705. + 22 5
  3706. + 23 2
  3707. + 25 1
  3708. +
  3709. +
  3710. +* Wakeup latency of a selected process
  3711. +
  3712. +To only collect wakeup latency data of a particular process, write the
  3713. +PID of the requested process to
  3714. +
  3715. +/sys/kernel/debug/tracing/latency_hist/wakeup/pid
  3716. +
  3717. +PIDs are not considered, if this variable is set to 0.
  3718. +
  3719. +
  3720. +* Details of the process with the highest wakeup latency so far
  3721. +
  3722. +Selected data of the process that suffered from the highest wakeup
  3723. +latency that occurred in a particular CPU are available in the file
  3724. +
  3725. +/sys/kernel/debug/tracing/latency_hist/wakeup/max_latency-CPUx.
  3726. +
  3727. +In addition, other relevant system data at the time when the
  3728. +latency occurred are given.
  3729. +
  3730. +The format of the data is (all in one line):
  3731. +<PID> <Priority> <Latency> (<Timeroffset>) <Command> \
  3732. +<- <PID> <Priority> <Command> <Timestamp>
  3733. +
  3734. +The value of <Timeroffset> is only relevant in the combined timer
  3735. +and wakeup latency recording. In the wakeup recording, it is
  3736. +always 0, in the missed_timer_offsets recording, it is the same
  3737. +as <Latency>.
  3738. +
  3739. +When retrospectively searching for the origin of a latency and
  3740. +tracing was not enabled, it may be helpful to know the name and
  3741. +some basic data of the task that (finally) was switching to the
  3742. +late real-tlme task. In addition to the victim's data, also the
  3743. +data of the possible culprit are therefore displayed after the
  3744. +"<-" symbol.
  3745. +
  3746. +Finally, the timestamp of the time when the latency occurred
  3747. +in <seconds>.<microseconds> after the most recent system boot
  3748. +is provided.
  3749. +
  3750. +These data are also reset when the wakeup histogram is reset.
  3751. diff -Nur linux-4.4.13.orig/drivers/acpi/acpica/acglobal.h linux-4.4.13/drivers/acpi/acpica/acglobal.h
  3752. --- linux-4.4.13.orig/drivers/acpi/acpica/acglobal.h 2016-06-08 03:14:51.000000000 +0200
  3753. +++ linux-4.4.13/drivers/acpi/acpica/acglobal.h 2016-06-22 21:55:07.994523867 +0200
  3754. @@ -116,7 +116,7 @@
  3755. * interrupt level
  3756. */
  3757. ACPI_GLOBAL(acpi_spinlock, acpi_gbl_gpe_lock); /* For GPE data structs and registers */
  3758. -ACPI_GLOBAL(acpi_spinlock, acpi_gbl_hardware_lock); /* For ACPI H/W except GPE registers */
  3759. +ACPI_GLOBAL(acpi_raw_spinlock, acpi_gbl_hardware_lock); /* For ACPI H/W except GPE registers */
  3760. ACPI_GLOBAL(acpi_spinlock, acpi_gbl_reference_count_lock);
  3761. /* Mutex for _OSI support */
  3762. diff -Nur linux-4.4.13.orig/drivers/acpi/acpica/hwregs.c linux-4.4.13/drivers/acpi/acpica/hwregs.c
  3763. --- linux-4.4.13.orig/drivers/acpi/acpica/hwregs.c 2016-06-08 03:14:51.000000000 +0200
  3764. +++ linux-4.4.13/drivers/acpi/acpica/hwregs.c 2016-06-22 21:55:07.994523867 +0200
  3765. @@ -269,14 +269,14 @@
  3766. ACPI_BITMASK_ALL_FIXED_STATUS,
  3767. ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address)));
  3768. - lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
  3769. + raw_spin_lock_irqsave(acpi_gbl_hardware_lock, lock_flags);
  3770. /* Clear the fixed events in PM1 A/B */
  3771. status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
  3772. ACPI_BITMASK_ALL_FIXED_STATUS);
  3773. - acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
  3774. + raw_spin_unlock_irqrestore(acpi_gbl_hardware_lock, lock_flags);
  3775. if (ACPI_FAILURE(status)) {
  3776. goto exit;
  3777. diff -Nur linux-4.4.13.orig/drivers/acpi/acpica/hwxface.c linux-4.4.13/drivers/acpi/acpica/hwxface.c
  3778. --- linux-4.4.13.orig/drivers/acpi/acpica/hwxface.c 2016-06-08 03:14:51.000000000 +0200
  3779. +++ linux-4.4.13/drivers/acpi/acpica/hwxface.c 2016-06-22 21:55:07.994523867 +0200
  3780. @@ -374,7 +374,7 @@
  3781. return_ACPI_STATUS(AE_BAD_PARAMETER);
  3782. }
  3783. - lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
  3784. + raw_spin_lock_irqsave(acpi_gbl_hardware_lock, lock_flags);
  3785. /*
  3786. * At this point, we know that the parent register is one of the
  3787. @@ -435,7 +435,7 @@
  3788. unlock_and_exit:
  3789. - acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
  3790. + raw_spin_unlock_irqrestore(acpi_gbl_hardware_lock, lock_flags);
  3791. return_ACPI_STATUS(status);
  3792. }
  3793. diff -Nur linux-4.4.13.orig/drivers/acpi/acpica/utmutex.c linux-4.4.13/drivers/acpi/acpica/utmutex.c
  3794. --- linux-4.4.13.orig/drivers/acpi/acpica/utmutex.c 2016-06-08 03:14:51.000000000 +0200
  3795. +++ linux-4.4.13/drivers/acpi/acpica/utmutex.c 2016-06-22 21:55:07.994523867 +0200
  3796. @@ -88,7 +88,7 @@
  3797. return_ACPI_STATUS (status);
  3798. }
  3799. - status = acpi_os_create_lock (&acpi_gbl_hardware_lock);
  3800. + status = acpi_os_create_raw_lock (&acpi_gbl_hardware_lock);
  3801. if (ACPI_FAILURE (status)) {
  3802. return_ACPI_STATUS (status);
  3803. }
  3804. @@ -156,7 +156,7 @@
  3805. /* Delete the spinlocks */
  3806. acpi_os_delete_lock(acpi_gbl_gpe_lock);
  3807. - acpi_os_delete_lock(acpi_gbl_hardware_lock);
  3808. + acpi_os_delete_raw_lock(acpi_gbl_hardware_lock);
  3809. acpi_os_delete_lock(acpi_gbl_reference_count_lock);
  3810. /* Delete the reader/writer lock */
  3811. diff -Nur linux-4.4.13.orig/drivers/ata/libata-sff.c linux-4.4.13/drivers/ata/libata-sff.c
  3812. --- linux-4.4.13.orig/drivers/ata/libata-sff.c 2016-06-08 03:14:51.000000000 +0200
  3813. +++ linux-4.4.13/drivers/ata/libata-sff.c 2016-06-22 21:55:07.994523867 +0200
  3814. @@ -678,9 +678,9 @@
  3815. unsigned long flags;
  3816. unsigned int consumed;
  3817. - local_irq_save(flags);
  3818. + local_irq_save_nort(flags);
  3819. consumed = ata_sff_data_xfer32(dev, buf, buflen, rw);
  3820. - local_irq_restore(flags);
  3821. + local_irq_restore_nort(flags);
  3822. return consumed;
  3823. }
  3824. @@ -719,7 +719,7 @@
  3825. unsigned long flags;
  3826. /* FIXME: use a bounce buffer */
  3827. - local_irq_save(flags);
  3828. + local_irq_save_nort(flags);
  3829. buf = kmap_atomic(page);
  3830. /* do the actual data transfer */
  3831. @@ -727,7 +727,7 @@
  3832. do_write);
  3833. kunmap_atomic(buf);
  3834. - local_irq_restore(flags);
  3835. + local_irq_restore_nort(flags);
  3836. } else {
  3837. buf = page_address(page);
  3838. ap->ops->sff_data_xfer(qc->dev, buf + offset, qc->sect_size,
  3839. @@ -864,7 +864,7 @@
  3840. unsigned long flags;
  3841. /* FIXME: use bounce buffer */
  3842. - local_irq_save(flags);
  3843. + local_irq_save_nort(flags);
  3844. buf = kmap_atomic(page);
  3845. /* do the actual data transfer */
  3846. @@ -872,7 +872,7 @@
  3847. count, rw);
  3848. kunmap_atomic(buf);
  3849. - local_irq_restore(flags);
  3850. + local_irq_restore_nort(flags);
  3851. } else {
  3852. buf = page_address(page);
  3853. consumed = ap->ops->sff_data_xfer(dev, buf + offset,
  3854. diff -Nur linux-4.4.13.orig/drivers/block/zram/zram_drv.c linux-4.4.13/drivers/block/zram/zram_drv.c
  3855. --- linux-4.4.13.orig/drivers/block/zram/zram_drv.c 2016-06-08 03:14:51.000000000 +0200
  3856. +++ linux-4.4.13/drivers/block/zram/zram_drv.c 2016-06-22 21:55:07.994523867 +0200
  3857. @@ -520,6 +520,8 @@
  3858. goto out_error;
  3859. }
  3860. + zram_meta_init_table_locks(meta, disksize);
  3861. +
  3862. return meta;
  3863. out_error:
  3864. @@ -568,12 +570,12 @@
  3865. unsigned long handle;
  3866. size_t size;
  3867. - bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
  3868. + zram_lock_table(&meta->table[index]);
  3869. handle = meta->table[index].handle;
  3870. size = zram_get_obj_size(meta, index);
  3871. if (!handle || zram_test_flag(meta, index, ZRAM_ZERO)) {
  3872. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3873. + zram_unlock_table(&meta->table[index]);
  3874. clear_page(mem);
  3875. return 0;
  3876. }
  3877. @@ -584,7 +586,7 @@
  3878. else
  3879. ret = zcomp_decompress(zram->comp, cmem, size, mem);
  3880. zs_unmap_object(meta->mem_pool, handle);
  3881. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3882. + zram_unlock_table(&meta->table[index]);
  3883. /* Should NEVER happen. Return bio error if it does. */
  3884. if (unlikely(ret)) {
  3885. @@ -604,14 +606,14 @@
  3886. struct zram_meta *meta = zram->meta;
  3887. page = bvec->bv_page;
  3888. - bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
  3889. + zram_lock_table(&meta->table[index]);
  3890. if (unlikely(!meta->table[index].handle) ||
  3891. zram_test_flag(meta, index, ZRAM_ZERO)) {
  3892. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3893. + zram_unlock_table(&meta->table[index]);
  3894. handle_zero_page(bvec);
  3895. return 0;
  3896. }
  3897. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3898. + zram_unlock_table(&meta->table[index]);
  3899. if (is_partial_io(bvec))
  3900. /* Use a temporary buffer to decompress the page */
  3901. @@ -689,10 +691,10 @@
  3902. if (user_mem)
  3903. kunmap_atomic(user_mem);
  3904. /* Free memory associated with this sector now. */
  3905. - bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
  3906. + zram_lock_table(&meta->table[index]);
  3907. zram_free_page(zram, index);
  3908. zram_set_flag(meta, index, ZRAM_ZERO);
  3909. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3910. + zram_unlock_table(&meta->table[index]);
  3911. atomic64_inc(&zram->stats.zero_pages);
  3912. ret = 0;
  3913. @@ -752,12 +754,12 @@
  3914. * Free memory associated with this sector
  3915. * before overwriting unused sectors.
  3916. */
  3917. - bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
  3918. + zram_lock_table(&meta->table[index]);
  3919. zram_free_page(zram, index);
  3920. meta->table[index].handle = handle;
  3921. zram_set_obj_size(meta, index, clen);
  3922. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3923. + zram_unlock_table(&meta->table[index]);
  3924. /* Update stats */
  3925. atomic64_add(clen, &zram->stats.compr_data_size);
  3926. @@ -800,9 +802,9 @@
  3927. }
  3928. while (n >= PAGE_SIZE) {
  3929. - bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
  3930. + zram_lock_table(&meta->table[index]);
  3931. zram_free_page(zram, index);
  3932. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3933. + zram_unlock_table(&meta->table[index]);
  3934. atomic64_inc(&zram->stats.notify_free);
  3935. index++;
  3936. n -= PAGE_SIZE;
  3937. @@ -928,9 +930,9 @@
  3938. zram = bdev->bd_disk->private_data;
  3939. meta = zram->meta;
  3940. - bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
  3941. + zram_lock_table(&meta->table[index]);
  3942. zram_free_page(zram, index);
  3943. - bit_spin_unlock(ZRAM_ACCESS, &meta->table[index].value);
  3944. + zram_unlock_table(&meta->table[index]);
  3945. atomic64_inc(&zram->stats.notify_free);
  3946. }
  3947. diff -Nur linux-4.4.13.orig/drivers/block/zram/zram_drv.h linux-4.4.13/drivers/block/zram/zram_drv.h
  3948. --- linux-4.4.13.orig/drivers/block/zram/zram_drv.h 2016-06-08 03:14:51.000000000 +0200
  3949. +++ linux-4.4.13/drivers/block/zram/zram_drv.h 2016-06-22 21:55:07.994523867 +0200
  3950. @@ -72,6 +72,9 @@
  3951. struct zram_table_entry {
  3952. unsigned long handle;
  3953. unsigned long value;
  3954. +#ifdef CONFIG_PREEMPT_RT_BASE
  3955. + spinlock_t lock;
  3956. +#endif
  3957. };
  3958. struct zram_stats {
  3959. @@ -119,4 +122,42 @@
  3960. */
  3961. bool claim; /* Protected by bdev->bd_mutex */
  3962. };
  3963. +
  3964. +#ifndef CONFIG_PREEMPT_RT_BASE
  3965. +static inline void zram_lock_table(struct zram_table_entry *table)
  3966. +{
  3967. + bit_spin_lock(ZRAM_ACCESS, &table->value);
  3968. +}
  3969. +
  3970. +static inline void zram_unlock_table(struct zram_table_entry *table)
  3971. +{
  3972. + bit_spin_unlock(ZRAM_ACCESS, &table->value);
  3973. +}
  3974. +
  3975. +static inline void zram_meta_init_table_locks(struct zram_meta *meta, u64 disksize) { }
  3976. +#else /* CONFIG_PREEMPT_RT_BASE */
  3977. +static inline void zram_lock_table(struct zram_table_entry *table)
  3978. +{
  3979. + spin_lock(&table->lock);
  3980. + __set_bit(ZRAM_ACCESS, &table->value);
  3981. +}
  3982. +
  3983. +static inline void zram_unlock_table(struct zram_table_entry *table)
  3984. +{
  3985. + __clear_bit(ZRAM_ACCESS, &table->value);
  3986. + spin_unlock(&table->lock);
  3987. +}
  3988. +
  3989. +static inline void zram_meta_init_table_locks(struct zram_meta *meta, u64 disksize)
  3990. +{
  3991. + size_t num_pages = disksize >> PAGE_SHIFT;
  3992. + size_t index;
  3993. +
  3994. + for (index = 0; index < num_pages; index++) {
  3995. + spinlock_t *lock = &meta->table[index].lock;
  3996. + spin_lock_init(lock);
  3997. + }
  3998. +}
  3999. +#endif /* CONFIG_PREEMPT_RT_BASE */
  4000. +
  4001. #endif
  4002. diff -Nur linux-4.4.13.orig/drivers/char/random.c linux-4.4.13/drivers/char/random.c
  4003. --- linux-4.4.13.orig/drivers/char/random.c 2016-06-08 03:14:51.000000000 +0200
  4004. +++ linux-4.4.13/drivers/char/random.c 2016-06-22 21:55:07.994523867 +0200
  4005. @@ -796,8 +796,6 @@
  4006. } sample;
  4007. long delta, delta2, delta3;
  4008. - preempt_disable();
  4009. -
  4010. sample.jiffies = jiffies;
  4011. sample.cycles = random_get_entropy();
  4012. sample.num = num;
  4013. @@ -838,7 +836,6 @@
  4014. */
  4015. credit_entropy_bits(r, min_t(int, fls(delta>>1), 11));
  4016. }
  4017. - preempt_enable();
  4018. }
  4019. void add_input_randomness(unsigned int type, unsigned int code,
  4020. @@ -891,28 +888,27 @@
  4021. return *(ptr + f->reg_idx++);
  4022. }
  4023. -void add_interrupt_randomness(int irq, int irq_flags)
  4024. +void add_interrupt_randomness(int irq, int irq_flags, __u64 ip)
  4025. {
  4026. struct entropy_store *r;
  4027. struct fast_pool *fast_pool = this_cpu_ptr(&irq_randomness);
  4028. - struct pt_regs *regs = get_irq_regs();
  4029. unsigned long now = jiffies;
  4030. cycles_t cycles = random_get_entropy();
  4031. __u32 c_high, j_high;
  4032. - __u64 ip;
  4033. unsigned long seed;
  4034. int credit = 0;
  4035. if (cycles == 0)
  4036. - cycles = get_reg(fast_pool, regs);
  4037. + cycles = get_reg(fast_pool, NULL);
  4038. c_high = (sizeof(cycles) > 4) ? cycles >> 32 : 0;
  4039. j_high = (sizeof(now) > 4) ? now >> 32 : 0;
  4040. fast_pool->pool[0] ^= cycles ^ j_high ^ irq;
  4041. fast_pool->pool[1] ^= now ^ c_high;
  4042. - ip = regs ? instruction_pointer(regs) : _RET_IP_;
  4043. + if (!ip)
  4044. + ip = _RET_IP_;
  4045. fast_pool->pool[2] ^= ip;
  4046. fast_pool->pool[3] ^= (sizeof(ip) > 4) ? ip >> 32 :
  4047. - get_reg(fast_pool, regs);
  4048. + get_reg(fast_pool, NULL);
  4049. fast_mix(fast_pool);
  4050. add_interrupt_bench(cycles);
  4051. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-generated.c linux-4.4.13/drivers/clk/at91/clk-generated.c
  4052. --- linux-4.4.13.orig/drivers/clk/at91/clk-generated.c 2016-06-08 03:14:51.000000000 +0200
  4053. +++ linux-4.4.13/drivers/clk/at91/clk-generated.c 2016-06-22 21:55:07.994523867 +0200
  4054. @@ -15,8 +15,8 @@
  4055. #include <linux/clkdev.h>
  4056. #include <linux/clk/at91_pmc.h>
  4057. #include <linux/of.h>
  4058. -#include <linux/of_address.h>
  4059. -#include <linux/io.h>
  4060. +#include <linux/mfd/syscon.h>
  4061. +#include <linux/regmap.h>
  4062. #include "pmc.h"
  4063. @@ -28,8 +28,9 @@
  4064. struct clk_generated {
  4065. struct clk_hw hw;
  4066. - struct at91_pmc *pmc;
  4067. + struct regmap *regmap;
  4068. struct clk_range range;
  4069. + spinlock_t *lock;
  4070. u32 id;
  4071. u32 gckdiv;
  4072. u8 parent_id;
  4073. @@ -41,49 +42,52 @@
  4074. static int clk_generated_enable(struct clk_hw *hw)
  4075. {
  4076. struct clk_generated *gck = to_clk_generated(hw);
  4077. - struct at91_pmc *pmc = gck->pmc;
  4078. - u32 tmp;
  4079. + unsigned long flags;
  4080. pr_debug("GCLK: %s, gckdiv = %d, parent id = %d\n",
  4081. __func__, gck->gckdiv, gck->parent_id);
  4082. - pmc_lock(pmc);
  4083. - pmc_write(pmc, AT91_PMC_PCR, (gck->id & AT91_PMC_PCR_PID_MASK));
  4084. - tmp = pmc_read(pmc, AT91_PMC_PCR) &
  4085. - ~(AT91_PMC_PCR_GCKDIV_MASK | AT91_PMC_PCR_GCKCSS_MASK);
  4086. - pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_GCKCSS(gck->parent_id)
  4087. - | AT91_PMC_PCR_CMD
  4088. - | AT91_PMC_PCR_GCKDIV(gck->gckdiv)
  4089. - | AT91_PMC_PCR_GCKEN);
  4090. - pmc_unlock(pmc);
  4091. + spin_lock_irqsave(gck->lock, flags);
  4092. + regmap_write(gck->regmap, AT91_PMC_PCR,
  4093. + (gck->id & AT91_PMC_PCR_PID_MASK));
  4094. + regmap_update_bits(gck->regmap, AT91_PMC_PCR,
  4095. + AT91_PMC_PCR_GCKDIV_MASK | AT91_PMC_PCR_GCKCSS_MASK |
  4096. + AT91_PMC_PCR_CMD | AT91_PMC_PCR_GCKEN,
  4097. + AT91_PMC_PCR_GCKCSS(gck->parent_id) |
  4098. + AT91_PMC_PCR_CMD |
  4099. + AT91_PMC_PCR_GCKDIV(gck->gckdiv) |
  4100. + AT91_PMC_PCR_GCKEN);
  4101. + spin_unlock_irqrestore(gck->lock, flags);
  4102. return 0;
  4103. }
  4104. static void clk_generated_disable(struct clk_hw *hw)
  4105. {
  4106. struct clk_generated *gck = to_clk_generated(hw);
  4107. - struct at91_pmc *pmc = gck->pmc;
  4108. - u32 tmp;
  4109. + unsigned long flags;
  4110. - pmc_lock(pmc);
  4111. - pmc_write(pmc, AT91_PMC_PCR, (gck->id & AT91_PMC_PCR_PID_MASK));
  4112. - tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_GCKEN;
  4113. - pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_CMD);
  4114. - pmc_unlock(pmc);
  4115. + spin_lock_irqsave(gck->lock, flags);
  4116. + regmap_write(gck->regmap, AT91_PMC_PCR,
  4117. + (gck->id & AT91_PMC_PCR_PID_MASK));
  4118. + regmap_update_bits(gck->regmap, AT91_PMC_PCR,
  4119. + AT91_PMC_PCR_CMD | AT91_PMC_PCR_GCKEN,
  4120. + AT91_PMC_PCR_CMD);
  4121. + spin_unlock_irqrestore(gck->lock, flags);
  4122. }
  4123. static int clk_generated_is_enabled(struct clk_hw *hw)
  4124. {
  4125. struct clk_generated *gck = to_clk_generated(hw);
  4126. - struct at91_pmc *pmc = gck->pmc;
  4127. - int ret;
  4128. + unsigned long flags;
  4129. + unsigned int status;
  4130. - pmc_lock(pmc);
  4131. - pmc_write(pmc, AT91_PMC_PCR, (gck->id & AT91_PMC_PCR_PID_MASK));
  4132. - ret = !!(pmc_read(pmc, AT91_PMC_PCR) & AT91_PMC_PCR_GCKEN);
  4133. - pmc_unlock(pmc);
  4134. + spin_lock_irqsave(gck->lock, flags);
  4135. + regmap_write(gck->regmap, AT91_PMC_PCR,
  4136. + (gck->id & AT91_PMC_PCR_PID_MASK));
  4137. + regmap_read(gck->regmap, AT91_PMC_PCR, &status);
  4138. + spin_unlock_irqrestore(gck->lock, flags);
  4139. - return ret;
  4140. + return status & AT91_PMC_PCR_GCKEN ? 1 : 0;
  4141. }
  4142. static unsigned long
  4143. @@ -214,13 +218,14 @@
  4144. */
  4145. static void clk_generated_startup(struct clk_generated *gck)
  4146. {
  4147. - struct at91_pmc *pmc = gck->pmc;
  4148. u32 tmp;
  4149. + unsigned long flags;
  4150. - pmc_lock(pmc);
  4151. - pmc_write(pmc, AT91_PMC_PCR, (gck->id & AT91_PMC_PCR_PID_MASK));
  4152. - tmp = pmc_read(pmc, AT91_PMC_PCR);
  4153. - pmc_unlock(pmc);
  4154. + spin_lock_irqsave(gck->lock, flags);
  4155. + regmap_write(gck->regmap, AT91_PMC_PCR,
  4156. + (gck->id & AT91_PMC_PCR_PID_MASK));
  4157. + regmap_read(gck->regmap, AT91_PMC_PCR, &tmp);
  4158. + spin_unlock_irqrestore(gck->lock, flags);
  4159. gck->parent_id = (tmp & AT91_PMC_PCR_GCKCSS_MASK)
  4160. >> AT91_PMC_PCR_GCKCSS_OFFSET;
  4161. @@ -229,8 +234,8 @@
  4162. }
  4163. static struct clk * __init
  4164. -at91_clk_register_generated(struct at91_pmc *pmc, const char *name,
  4165. - const char **parent_names, u8 num_parents,
  4166. +at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, const char
  4167. + *name, const char **parent_names, u8 num_parents,
  4168. u8 id, const struct clk_range *range)
  4169. {
  4170. struct clk_generated *gck;
  4171. @@ -249,7 +254,8 @@
  4172. gck->id = id;
  4173. gck->hw.init = &init;
  4174. - gck->pmc = pmc;
  4175. + gck->regmap = regmap;
  4176. + gck->lock = lock;
  4177. gck->range = *range;
  4178. clk = clk_register(NULL, &gck->hw);
  4179. @@ -261,8 +267,7 @@
  4180. return clk;
  4181. }
  4182. -void __init of_sama5d2_clk_generated_setup(struct device_node *np,
  4183. - struct at91_pmc *pmc)
  4184. +void __init of_sama5d2_clk_generated_setup(struct device_node *np)
  4185. {
  4186. int num;
  4187. u32 id;
  4188. @@ -272,6 +277,7 @@
  4189. const char *parent_names[GENERATED_SOURCE_MAX];
  4190. struct device_node *gcknp;
  4191. struct clk_range range = CLK_RANGE(0, 0);
  4192. + struct regmap *regmap;
  4193. num_parents = of_clk_get_parent_count(np);
  4194. if (num_parents <= 0 || num_parents > GENERATED_SOURCE_MAX)
  4195. @@ -283,6 +289,10 @@
  4196. if (!num || num > PERIPHERAL_MAX)
  4197. return;
  4198. + regmap = syscon_node_to_regmap(of_get_parent(np));
  4199. + if (IS_ERR(regmap))
  4200. + return;
  4201. +
  4202. for_each_child_of_node(np, gcknp) {
  4203. if (of_property_read_u32(gcknp, "reg", &id))
  4204. continue;
  4205. @@ -296,11 +306,14 @@
  4206. of_at91_get_clk_range(gcknp, "atmel,clk-output-range",
  4207. &range);
  4208. - clk = at91_clk_register_generated(pmc, name, parent_names,
  4209. - num_parents, id, &range);
  4210. + clk = at91_clk_register_generated(regmap, &pmc_pcr_lock, name,
  4211. + parent_names, num_parents,
  4212. + id, &range);
  4213. if (IS_ERR(clk))
  4214. continue;
  4215. of_clk_add_provider(gcknp, of_clk_src_simple_get, clk);
  4216. }
  4217. }
  4218. +CLK_OF_DECLARE(of_sama5d2_clk_generated_setup, "atmel,sama5d2-clk-generated",
  4219. + of_sama5d2_clk_generated_setup);
  4220. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-h32mx.c linux-4.4.13/drivers/clk/at91/clk-h32mx.c
  4221. --- linux-4.4.13.orig/drivers/clk/at91/clk-h32mx.c 2016-06-08 03:14:51.000000000 +0200
  4222. +++ linux-4.4.13/drivers/clk/at91/clk-h32mx.c 2016-06-22 21:55:07.994523867 +0200
  4223. @@ -15,15 +15,9 @@
  4224. #include <linux/clk-provider.h>
  4225. #include <linux/clkdev.h>
  4226. #include <linux/clk/at91_pmc.h>
  4227. -#include <linux/delay.h>
  4228. #include <linux/of.h>
  4229. -#include <linux/of_address.h>
  4230. -#include <linux/of_irq.h>
  4231. -#include <linux/io.h>
  4232. -#include <linux/interrupt.h>
  4233. -#include <linux/irq.h>
  4234. -#include <linux/sched.h>
  4235. -#include <linux/wait.h>
  4236. +#include <linux/regmap.h>
  4237. +#include <linux/mfd/syscon.h>
  4238. #include "pmc.h"
  4239. @@ -31,7 +25,7 @@
  4240. struct clk_sama5d4_h32mx {
  4241. struct clk_hw hw;
  4242. - struct at91_pmc *pmc;
  4243. + struct regmap *regmap;
  4244. };
  4245. #define to_clk_sama5d4_h32mx(hw) container_of(hw, struct clk_sama5d4_h32mx, hw)
  4246. @@ -40,8 +34,10 @@
  4247. unsigned long parent_rate)
  4248. {
  4249. struct clk_sama5d4_h32mx *h32mxclk = to_clk_sama5d4_h32mx(hw);
  4250. + unsigned int mckr;
  4251. - if (pmc_read(h32mxclk->pmc, AT91_PMC_MCKR) & AT91_PMC_H32MXDIV)
  4252. + regmap_read(h32mxclk->regmap, AT91_PMC_MCKR, &mckr);
  4253. + if (mckr & AT91_PMC_H32MXDIV)
  4254. return parent_rate / 2;
  4255. if (parent_rate > H32MX_MAX_FREQ)
  4256. @@ -70,18 +66,16 @@
  4257. unsigned long parent_rate)
  4258. {
  4259. struct clk_sama5d4_h32mx *h32mxclk = to_clk_sama5d4_h32mx(hw);
  4260. - struct at91_pmc *pmc = h32mxclk->pmc;
  4261. - u32 tmp;
  4262. + u32 mckr = 0;
  4263. if (parent_rate != rate && (parent_rate / 2) != rate)
  4264. return -EINVAL;
  4265. - pmc_lock(pmc);
  4266. - tmp = pmc_read(pmc, AT91_PMC_MCKR) & ~AT91_PMC_H32MXDIV;
  4267. if ((parent_rate / 2) == rate)
  4268. - tmp |= AT91_PMC_H32MXDIV;
  4269. - pmc_write(pmc, AT91_PMC_MCKR, tmp);
  4270. - pmc_unlock(pmc);
  4271. + mckr = AT91_PMC_H32MXDIV;
  4272. +
  4273. + regmap_update_bits(h32mxclk->regmap, AT91_PMC_MCKR,
  4274. + AT91_PMC_H32MXDIV, mckr);
  4275. return 0;
  4276. }
  4277. @@ -92,14 +86,18 @@
  4278. .set_rate = clk_sama5d4_h32mx_set_rate,
  4279. };
  4280. -void __init of_sama5d4_clk_h32mx_setup(struct device_node *np,
  4281. - struct at91_pmc *pmc)
  4282. +static void __init of_sama5d4_clk_h32mx_setup(struct device_node *np)
  4283. {
  4284. struct clk_sama5d4_h32mx *h32mxclk;
  4285. struct clk_init_data init;
  4286. const char *parent_name;
  4287. + struct regmap *regmap;
  4288. struct clk *clk;
  4289. + regmap = syscon_node_to_regmap(of_get_parent(np));
  4290. + if (IS_ERR(regmap))
  4291. + return;
  4292. +
  4293. h32mxclk = kzalloc(sizeof(*h32mxclk), GFP_KERNEL);
  4294. if (!h32mxclk)
  4295. return;
  4296. @@ -113,7 +111,7 @@
  4297. init.flags = CLK_SET_RATE_GATE;
  4298. h32mxclk->hw.init = &init;
  4299. - h32mxclk->pmc = pmc;
  4300. + h32mxclk->regmap = regmap;
  4301. clk = clk_register(NULL, &h32mxclk->hw);
  4302. if (IS_ERR(clk)) {
  4303. @@ -123,3 +121,5 @@
  4304. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  4305. }
  4306. +CLK_OF_DECLARE(of_sama5d4_clk_h32mx_setup, "atmel,sama5d4-clk-h32mx",
  4307. + of_sama5d4_clk_h32mx_setup);
  4308. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-main.c linux-4.4.13/drivers/clk/at91/clk-main.c
  4309. --- linux-4.4.13.orig/drivers/clk/at91/clk-main.c 2016-06-08 03:14:51.000000000 +0200
  4310. +++ linux-4.4.13/drivers/clk/at91/clk-main.c 2016-06-22 21:55:07.994523867 +0200
  4311. @@ -13,13 +13,8 @@
  4312. #include <linux/clk/at91_pmc.h>
  4313. #include <linux/delay.h>
  4314. #include <linux/of.h>
  4315. -#include <linux/of_address.h>
  4316. -#include <linux/of_irq.h>
  4317. -#include <linux/io.h>
  4318. -#include <linux/interrupt.h>
  4319. -#include <linux/irq.h>
  4320. -#include <linux/sched.h>
  4321. -#include <linux/wait.h>
  4322. +#include <linux/mfd/syscon.h>
  4323. +#include <linux/regmap.h>
  4324. #include "pmc.h"
  4325. @@ -34,18 +29,14 @@
  4326. struct clk_main_osc {
  4327. struct clk_hw hw;
  4328. - struct at91_pmc *pmc;
  4329. - unsigned int irq;
  4330. - wait_queue_head_t wait;
  4331. + struct regmap *regmap;
  4332. };
  4333. #define to_clk_main_osc(hw) container_of(hw, struct clk_main_osc, hw)
  4334. struct clk_main_rc_osc {
  4335. struct clk_hw hw;
  4336. - struct at91_pmc *pmc;
  4337. - unsigned int irq;
  4338. - wait_queue_head_t wait;
  4339. + struct regmap *regmap;
  4340. unsigned long frequency;
  4341. unsigned long accuracy;
  4342. };
  4343. @@ -54,51 +45,47 @@
  4344. struct clk_rm9200_main {
  4345. struct clk_hw hw;
  4346. - struct at91_pmc *pmc;
  4347. + struct regmap *regmap;
  4348. };
  4349. #define to_clk_rm9200_main(hw) container_of(hw, struct clk_rm9200_main, hw)
  4350. struct clk_sam9x5_main {
  4351. struct clk_hw hw;
  4352. - struct at91_pmc *pmc;
  4353. - unsigned int irq;
  4354. - wait_queue_head_t wait;
  4355. + struct regmap *regmap;
  4356. u8 parent;
  4357. };
  4358. #define to_clk_sam9x5_main(hw) container_of(hw, struct clk_sam9x5_main, hw)
  4359. -static irqreturn_t clk_main_osc_irq_handler(int irq, void *dev_id)
  4360. +static inline bool clk_main_osc_ready(struct regmap *regmap)
  4361. {
  4362. - struct clk_main_osc *osc = dev_id;
  4363. + unsigned int status;
  4364. - wake_up(&osc->wait);
  4365. - disable_irq_nosync(osc->irq);
  4366. + regmap_read(regmap, AT91_PMC_SR, &status);
  4367. - return IRQ_HANDLED;
  4368. + return status & AT91_PMC_MOSCS;
  4369. }
  4370. static int clk_main_osc_prepare(struct clk_hw *hw)
  4371. {
  4372. struct clk_main_osc *osc = to_clk_main_osc(hw);
  4373. - struct at91_pmc *pmc = osc->pmc;
  4374. + struct regmap *regmap = osc->regmap;
  4375. u32 tmp;
  4376. - tmp = pmc_read(pmc, AT91_CKGR_MOR) & ~MOR_KEY_MASK;
  4377. + regmap_read(regmap, AT91_CKGR_MOR, &tmp);
  4378. + tmp &= ~MOR_KEY_MASK;
  4379. +
  4380. if (tmp & AT91_PMC_OSCBYPASS)
  4381. return 0;
  4382. if (!(tmp & AT91_PMC_MOSCEN)) {
  4383. tmp |= AT91_PMC_MOSCEN | AT91_PMC_KEY;
  4384. - pmc_write(pmc, AT91_CKGR_MOR, tmp);
  4385. + regmap_write(regmap, AT91_CKGR_MOR, tmp);
  4386. }
  4387. - while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCS)) {
  4388. - enable_irq(osc->irq);
  4389. - wait_event(osc->wait,
  4390. - pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCS);
  4391. - }
  4392. + while (!clk_main_osc_ready(regmap))
  4393. + cpu_relax();
  4394. return 0;
  4395. }
  4396. @@ -106,9 +93,10 @@
  4397. static void clk_main_osc_unprepare(struct clk_hw *hw)
  4398. {
  4399. struct clk_main_osc *osc = to_clk_main_osc(hw);
  4400. - struct at91_pmc *pmc = osc->pmc;
  4401. - u32 tmp = pmc_read(pmc, AT91_CKGR_MOR);
  4402. + struct regmap *regmap = osc->regmap;
  4403. + u32 tmp;
  4404. + regmap_read(regmap, AT91_CKGR_MOR, &tmp);
  4405. if (tmp & AT91_PMC_OSCBYPASS)
  4406. return;
  4407. @@ -116,20 +104,22 @@
  4408. return;
  4409. tmp &= ~(AT91_PMC_KEY | AT91_PMC_MOSCEN);
  4410. - pmc_write(pmc, AT91_CKGR_MOR, tmp | AT91_PMC_KEY);
  4411. + regmap_write(regmap, AT91_CKGR_MOR, tmp | AT91_PMC_KEY);
  4412. }
  4413. static int clk_main_osc_is_prepared(struct clk_hw *hw)
  4414. {
  4415. struct clk_main_osc *osc = to_clk_main_osc(hw);
  4416. - struct at91_pmc *pmc = osc->pmc;
  4417. - u32 tmp = pmc_read(pmc, AT91_CKGR_MOR);
  4418. + struct regmap *regmap = osc->regmap;
  4419. + u32 tmp, status;
  4420. + regmap_read(regmap, AT91_CKGR_MOR, &tmp);
  4421. if (tmp & AT91_PMC_OSCBYPASS)
  4422. return 1;
  4423. - return !!((pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCS) &&
  4424. - (pmc_read(pmc, AT91_CKGR_MOR) & AT91_PMC_MOSCEN));
  4425. + regmap_read(regmap, AT91_PMC_SR, &status);
  4426. +
  4427. + return (status & AT91_PMC_MOSCS) && (tmp & AT91_PMC_MOSCEN);
  4428. }
  4429. static const struct clk_ops main_osc_ops = {
  4430. @@ -139,18 +129,16 @@
  4431. };
  4432. static struct clk * __init
  4433. -at91_clk_register_main_osc(struct at91_pmc *pmc,
  4434. - unsigned int irq,
  4435. +at91_clk_register_main_osc(struct regmap *regmap,
  4436. const char *name,
  4437. const char *parent_name,
  4438. bool bypass)
  4439. {
  4440. - int ret;
  4441. struct clk_main_osc *osc;
  4442. struct clk *clk = NULL;
  4443. struct clk_init_data init;
  4444. - if (!pmc || !irq || !name || !parent_name)
  4445. + if (!name || !parent_name)
  4446. return ERR_PTR(-EINVAL);
  4447. osc = kzalloc(sizeof(*osc), GFP_KERNEL);
  4448. @@ -164,85 +152,70 @@
  4449. init.flags = CLK_IGNORE_UNUSED;
  4450. osc->hw.init = &init;
  4451. - osc->pmc = pmc;
  4452. - osc->irq = irq;
  4453. -
  4454. - init_waitqueue_head(&osc->wait);
  4455. - irq_set_status_flags(osc->irq, IRQ_NOAUTOEN);
  4456. - ret = request_irq(osc->irq, clk_main_osc_irq_handler,
  4457. - IRQF_TRIGGER_HIGH, name, osc);
  4458. - if (ret) {
  4459. - kfree(osc);
  4460. - return ERR_PTR(ret);
  4461. - }
  4462. + osc->regmap = regmap;
  4463. if (bypass)
  4464. - pmc_write(pmc, AT91_CKGR_MOR,
  4465. - (pmc_read(pmc, AT91_CKGR_MOR) &
  4466. - ~(MOR_KEY_MASK | AT91_PMC_MOSCEN)) |
  4467. - AT91_PMC_OSCBYPASS | AT91_PMC_KEY);
  4468. + regmap_update_bits(regmap,
  4469. + AT91_CKGR_MOR, MOR_KEY_MASK |
  4470. + AT91_PMC_MOSCEN,
  4471. + AT91_PMC_OSCBYPASS | AT91_PMC_KEY);
  4472. clk = clk_register(NULL, &osc->hw);
  4473. - if (IS_ERR(clk)) {
  4474. - free_irq(irq, osc);
  4475. + if (IS_ERR(clk))
  4476. kfree(osc);
  4477. - }
  4478. return clk;
  4479. }
  4480. -void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np,
  4481. - struct at91_pmc *pmc)
  4482. +static void __init of_at91rm9200_clk_main_osc_setup(struct device_node *np)
  4483. {
  4484. struct clk *clk;
  4485. - unsigned int irq;
  4486. const char *name = np->name;
  4487. const char *parent_name;
  4488. + struct regmap *regmap;
  4489. bool bypass;
  4490. of_property_read_string(np, "clock-output-names", &name);
  4491. bypass = of_property_read_bool(np, "atmel,osc-bypass");
  4492. parent_name = of_clk_get_parent_name(np, 0);
  4493. - irq = irq_of_parse_and_map(np, 0);
  4494. - if (!irq)
  4495. + regmap = syscon_node_to_regmap(of_get_parent(np));
  4496. + if (IS_ERR(regmap))
  4497. return;
  4498. - clk = at91_clk_register_main_osc(pmc, irq, name, parent_name, bypass);
  4499. + clk = at91_clk_register_main_osc(regmap, name, parent_name, bypass);
  4500. if (IS_ERR(clk))
  4501. return;
  4502. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  4503. }
  4504. +CLK_OF_DECLARE(at91rm9200_clk_main_osc, "atmel,at91rm9200-clk-main-osc",
  4505. + of_at91rm9200_clk_main_osc_setup);
  4506. -static irqreturn_t clk_main_rc_osc_irq_handler(int irq, void *dev_id)
  4507. +static bool clk_main_rc_osc_ready(struct regmap *regmap)
  4508. {
  4509. - struct clk_main_rc_osc *osc = dev_id;
  4510. + unsigned int status;
  4511. - wake_up(&osc->wait);
  4512. - disable_irq_nosync(osc->irq);
  4513. + regmap_read(regmap, AT91_PMC_SR, &status);
  4514. - return IRQ_HANDLED;
  4515. + return status & AT91_PMC_MOSCRCS;
  4516. }
  4517. static int clk_main_rc_osc_prepare(struct clk_hw *hw)
  4518. {
  4519. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  4520. - struct at91_pmc *pmc = osc->pmc;
  4521. - u32 tmp;
  4522. + struct regmap *regmap = osc->regmap;
  4523. + unsigned int mor;
  4524. - tmp = pmc_read(pmc, AT91_CKGR_MOR) & ~MOR_KEY_MASK;
  4525. + regmap_read(regmap, AT91_CKGR_MOR, &mor);
  4526. - if (!(tmp & AT91_PMC_MOSCRCEN)) {
  4527. - tmp |= AT91_PMC_MOSCRCEN | AT91_PMC_KEY;
  4528. - pmc_write(pmc, AT91_CKGR_MOR, tmp);
  4529. - }
  4530. + if (!(mor & AT91_PMC_MOSCRCEN))
  4531. + regmap_update_bits(regmap, AT91_CKGR_MOR,
  4532. + MOR_KEY_MASK | AT91_PMC_MOSCRCEN,
  4533. + AT91_PMC_MOSCRCEN | AT91_PMC_KEY);
  4534. - while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCRCS)) {
  4535. - enable_irq(osc->irq);
  4536. - wait_event(osc->wait,
  4537. - pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCRCS);
  4538. - }
  4539. + while (!clk_main_rc_osc_ready(regmap))
  4540. + cpu_relax();
  4541. return 0;
  4542. }
  4543. @@ -250,23 +223,28 @@
  4544. static void clk_main_rc_osc_unprepare(struct clk_hw *hw)
  4545. {
  4546. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  4547. - struct at91_pmc *pmc = osc->pmc;
  4548. - u32 tmp = pmc_read(pmc, AT91_CKGR_MOR);
  4549. + struct regmap *regmap = osc->regmap;
  4550. + unsigned int mor;
  4551. - if (!(tmp & AT91_PMC_MOSCRCEN))
  4552. + regmap_read(regmap, AT91_CKGR_MOR, &mor);
  4553. +
  4554. + if (!(mor & AT91_PMC_MOSCRCEN))
  4555. return;
  4556. - tmp &= ~(MOR_KEY_MASK | AT91_PMC_MOSCRCEN);
  4557. - pmc_write(pmc, AT91_CKGR_MOR, tmp | AT91_PMC_KEY);
  4558. + regmap_update_bits(regmap, AT91_CKGR_MOR,
  4559. + MOR_KEY_MASK | AT91_PMC_MOSCRCEN, AT91_PMC_KEY);
  4560. }
  4561. static int clk_main_rc_osc_is_prepared(struct clk_hw *hw)
  4562. {
  4563. struct clk_main_rc_osc *osc = to_clk_main_rc_osc(hw);
  4564. - struct at91_pmc *pmc = osc->pmc;
  4565. + struct regmap *regmap = osc->regmap;
  4566. + unsigned int mor, status;
  4567. +
  4568. + regmap_read(regmap, AT91_CKGR_MOR, &mor);
  4569. + regmap_read(regmap, AT91_PMC_SR, &status);
  4570. - return !!((pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCRCS) &&
  4571. - (pmc_read(pmc, AT91_CKGR_MOR) & AT91_PMC_MOSCRCEN));
  4572. + return (mor & AT91_PMC_MOSCRCEN) && (status & AT91_PMC_MOSCRCS);
  4573. }
  4574. static unsigned long clk_main_rc_osc_recalc_rate(struct clk_hw *hw,
  4575. @@ -294,17 +272,15 @@
  4576. };
  4577. static struct clk * __init
  4578. -at91_clk_register_main_rc_osc(struct at91_pmc *pmc,
  4579. - unsigned int irq,
  4580. +at91_clk_register_main_rc_osc(struct regmap *regmap,
  4581. const char *name,
  4582. u32 frequency, u32 accuracy)
  4583. {
  4584. - int ret;
  4585. struct clk_main_rc_osc *osc;
  4586. struct clk *clk = NULL;
  4587. struct clk_init_data init;
  4588. - if (!pmc || !irq || !name || !frequency)
  4589. + if (!name || !frequency)
  4590. return ERR_PTR(-EINVAL);
  4591. osc = kzalloc(sizeof(*osc), GFP_KERNEL);
  4592. @@ -318,63 +294,53 @@
  4593. init.flags = CLK_IS_ROOT | CLK_IGNORE_UNUSED;
  4594. osc->hw.init = &init;
  4595. - osc->pmc = pmc;
  4596. - osc->irq = irq;
  4597. + osc->regmap = regmap;
  4598. osc->frequency = frequency;
  4599. osc->accuracy = accuracy;
  4600. - init_waitqueue_head(&osc->wait);
  4601. - irq_set_status_flags(osc->irq, IRQ_NOAUTOEN);
  4602. - ret = request_irq(osc->irq, clk_main_rc_osc_irq_handler,
  4603. - IRQF_TRIGGER_HIGH, name, osc);
  4604. - if (ret)
  4605. - return ERR_PTR(ret);
  4606. -
  4607. clk = clk_register(NULL, &osc->hw);
  4608. - if (IS_ERR(clk)) {
  4609. - free_irq(irq, osc);
  4610. + if (IS_ERR(clk))
  4611. kfree(osc);
  4612. - }
  4613. return clk;
  4614. }
  4615. -void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np,
  4616. - struct at91_pmc *pmc)
  4617. +static void __init of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np)
  4618. {
  4619. struct clk *clk;
  4620. - unsigned int irq;
  4621. u32 frequency = 0;
  4622. u32 accuracy = 0;
  4623. const char *name = np->name;
  4624. + struct regmap *regmap;
  4625. of_property_read_string(np, "clock-output-names", &name);
  4626. of_property_read_u32(np, "clock-frequency", &frequency);
  4627. of_property_read_u32(np, "clock-accuracy", &accuracy);
  4628. - irq = irq_of_parse_and_map(np, 0);
  4629. - if (!irq)
  4630. + regmap = syscon_node_to_regmap(of_get_parent(np));
  4631. + if (IS_ERR(regmap))
  4632. return;
  4633. - clk = at91_clk_register_main_rc_osc(pmc, irq, name, frequency,
  4634. - accuracy);
  4635. + clk = at91_clk_register_main_rc_osc(regmap, name, frequency, accuracy);
  4636. if (IS_ERR(clk))
  4637. return;
  4638. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  4639. }
  4640. +CLK_OF_DECLARE(at91sam9x5_clk_main_rc_osc, "atmel,at91sam9x5-clk-main-rc-osc",
  4641. + of_at91sam9x5_clk_main_rc_osc_setup);
  4642. -static int clk_main_probe_frequency(struct at91_pmc *pmc)
  4643. +static int clk_main_probe_frequency(struct regmap *regmap)
  4644. {
  4645. unsigned long prep_time, timeout;
  4646. - u32 tmp;
  4647. + unsigned int mcfr;
  4648. timeout = jiffies + usecs_to_jiffies(MAINFRDY_TIMEOUT);
  4649. do {
  4650. prep_time = jiffies;
  4651. - tmp = pmc_read(pmc, AT91_CKGR_MCFR);
  4652. - if (tmp & AT91_PMC_MAINRDY)
  4653. + regmap_read(regmap, AT91_CKGR_MCFR, &mcfr);
  4654. + if (mcfr & AT91_PMC_MAINRDY)
  4655. return 0;
  4656. usleep_range(MAINF_LOOP_MIN_WAIT, MAINF_LOOP_MAX_WAIT);
  4657. } while (time_before(prep_time, timeout));
  4658. @@ -382,34 +348,37 @@
  4659. return -ETIMEDOUT;
  4660. }
  4661. -static unsigned long clk_main_recalc_rate(struct at91_pmc *pmc,
  4662. +static unsigned long clk_main_recalc_rate(struct regmap *regmap,
  4663. unsigned long parent_rate)
  4664. {
  4665. - u32 tmp;
  4666. + unsigned int mcfr;
  4667. if (parent_rate)
  4668. return parent_rate;
  4669. pr_warn("Main crystal frequency not set, using approximate value\n");
  4670. - tmp = pmc_read(pmc, AT91_CKGR_MCFR);
  4671. - if (!(tmp & AT91_PMC_MAINRDY))
  4672. + regmap_read(regmap, AT91_CKGR_MCFR, &mcfr);
  4673. + if (!(mcfr & AT91_PMC_MAINRDY))
  4674. return 0;
  4675. - return ((tmp & AT91_PMC_MAINF) * SLOW_CLOCK_FREQ) / MAINF_DIV;
  4676. + return ((mcfr & AT91_PMC_MAINF) * SLOW_CLOCK_FREQ) / MAINF_DIV;
  4677. }
  4678. static int clk_rm9200_main_prepare(struct clk_hw *hw)
  4679. {
  4680. struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw);
  4681. - return clk_main_probe_frequency(clkmain->pmc);
  4682. + return clk_main_probe_frequency(clkmain->regmap);
  4683. }
  4684. static int clk_rm9200_main_is_prepared(struct clk_hw *hw)
  4685. {
  4686. struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw);
  4687. + unsigned int status;
  4688. +
  4689. + regmap_read(clkmain->regmap, AT91_CKGR_MCFR, &status);
  4690. - return !!(pmc_read(clkmain->pmc, AT91_CKGR_MCFR) & AT91_PMC_MAINRDY);
  4691. + return status & AT91_PMC_MAINRDY ? 1 : 0;
  4692. }
  4693. static unsigned long clk_rm9200_main_recalc_rate(struct clk_hw *hw,
  4694. @@ -417,7 +386,7 @@
  4695. {
  4696. struct clk_rm9200_main *clkmain = to_clk_rm9200_main(hw);
  4697. - return clk_main_recalc_rate(clkmain->pmc, parent_rate);
  4698. + return clk_main_recalc_rate(clkmain->regmap, parent_rate);
  4699. }
  4700. static const struct clk_ops rm9200_main_ops = {
  4701. @@ -427,7 +396,7 @@
  4702. };
  4703. static struct clk * __init
  4704. -at91_clk_register_rm9200_main(struct at91_pmc *pmc,
  4705. +at91_clk_register_rm9200_main(struct regmap *regmap,
  4706. const char *name,
  4707. const char *parent_name)
  4708. {
  4709. @@ -435,7 +404,7 @@
  4710. struct clk *clk = NULL;
  4711. struct clk_init_data init;
  4712. - if (!pmc || !name)
  4713. + if (!name)
  4714. return ERR_PTR(-EINVAL);
  4715. if (!parent_name)
  4716. @@ -452,7 +421,7 @@
  4717. init.flags = 0;
  4718. clkmain->hw.init = &init;
  4719. - clkmain->pmc = pmc;
  4720. + clkmain->regmap = regmap;
  4721. clk = clk_register(NULL, &clkmain->hw);
  4722. if (IS_ERR(clk))
  4723. @@ -461,52 +430,54 @@
  4724. return clk;
  4725. }
  4726. -void __init of_at91rm9200_clk_main_setup(struct device_node *np,
  4727. - struct at91_pmc *pmc)
  4728. +static void __init of_at91rm9200_clk_main_setup(struct device_node *np)
  4729. {
  4730. struct clk *clk;
  4731. const char *parent_name;
  4732. const char *name = np->name;
  4733. + struct regmap *regmap;
  4734. parent_name = of_clk_get_parent_name(np, 0);
  4735. of_property_read_string(np, "clock-output-names", &name);
  4736. - clk = at91_clk_register_rm9200_main(pmc, name, parent_name);
  4737. + regmap = syscon_node_to_regmap(of_get_parent(np));
  4738. + if (IS_ERR(regmap))
  4739. + return;
  4740. +
  4741. + clk = at91_clk_register_rm9200_main(regmap, name, parent_name);
  4742. if (IS_ERR(clk))
  4743. return;
  4744. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  4745. }
  4746. +CLK_OF_DECLARE(at91rm9200_clk_main, "atmel,at91rm9200-clk-main",
  4747. + of_at91rm9200_clk_main_setup);
  4748. -static irqreturn_t clk_sam9x5_main_irq_handler(int irq, void *dev_id)
  4749. +static inline bool clk_sam9x5_main_ready(struct regmap *regmap)
  4750. {
  4751. - struct clk_sam9x5_main *clkmain = dev_id;
  4752. + unsigned int status;
  4753. - wake_up(&clkmain->wait);
  4754. - disable_irq_nosync(clkmain->irq);
  4755. + regmap_read(regmap, AT91_PMC_SR, &status);
  4756. - return IRQ_HANDLED;
  4757. + return status & AT91_PMC_MOSCSELS ? 1 : 0;
  4758. }
  4759. static int clk_sam9x5_main_prepare(struct clk_hw *hw)
  4760. {
  4761. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  4762. - struct at91_pmc *pmc = clkmain->pmc;
  4763. + struct regmap *regmap = clkmain->regmap;
  4764. - while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS)) {
  4765. - enable_irq(clkmain->irq);
  4766. - wait_event(clkmain->wait,
  4767. - pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS);
  4768. - }
  4769. + while (!clk_sam9x5_main_ready(regmap))
  4770. + cpu_relax();
  4771. - return clk_main_probe_frequency(pmc);
  4772. + return clk_main_probe_frequency(regmap);
  4773. }
  4774. static int clk_sam9x5_main_is_prepared(struct clk_hw *hw)
  4775. {
  4776. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  4777. - return !!(pmc_read(clkmain->pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS);
  4778. + return clk_sam9x5_main_ready(clkmain->regmap);
  4779. }
  4780. static unsigned long clk_sam9x5_main_recalc_rate(struct clk_hw *hw,
  4781. @@ -514,30 +485,28 @@
  4782. {
  4783. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  4784. - return clk_main_recalc_rate(clkmain->pmc, parent_rate);
  4785. + return clk_main_recalc_rate(clkmain->regmap, parent_rate);
  4786. }
  4787. static int clk_sam9x5_main_set_parent(struct clk_hw *hw, u8 index)
  4788. {
  4789. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  4790. - struct at91_pmc *pmc = clkmain->pmc;
  4791. - u32 tmp;
  4792. + struct regmap *regmap = clkmain->regmap;
  4793. + unsigned int tmp;
  4794. if (index > 1)
  4795. return -EINVAL;
  4796. - tmp = pmc_read(pmc, AT91_CKGR_MOR) & ~MOR_KEY_MASK;
  4797. + regmap_read(regmap, AT91_CKGR_MOR, &tmp);
  4798. + tmp &= ~MOR_KEY_MASK;
  4799. if (index && !(tmp & AT91_PMC_MOSCSEL))
  4800. - pmc_write(pmc, AT91_CKGR_MOR, tmp | AT91_PMC_MOSCSEL);
  4801. + regmap_write(regmap, AT91_CKGR_MOR, tmp | AT91_PMC_MOSCSEL);
  4802. else if (!index && (tmp & AT91_PMC_MOSCSEL))
  4803. - pmc_write(pmc, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL);
  4804. + regmap_write(regmap, AT91_CKGR_MOR, tmp & ~AT91_PMC_MOSCSEL);
  4805. - while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS)) {
  4806. - enable_irq(clkmain->irq);
  4807. - wait_event(clkmain->wait,
  4808. - pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MOSCSELS);
  4809. - }
  4810. + while (!clk_sam9x5_main_ready(regmap))
  4811. + cpu_relax();
  4812. return 0;
  4813. }
  4814. @@ -545,8 +514,11 @@
  4815. static u8 clk_sam9x5_main_get_parent(struct clk_hw *hw)
  4816. {
  4817. struct clk_sam9x5_main *clkmain = to_clk_sam9x5_main(hw);
  4818. + unsigned int status;
  4819. +
  4820. + regmap_read(clkmain->regmap, AT91_CKGR_MOR, &status);
  4821. - return !!(pmc_read(clkmain->pmc, AT91_CKGR_MOR) & AT91_PMC_MOSCEN);
  4822. + return status & AT91_PMC_MOSCEN ? 1 : 0;
  4823. }
  4824. static const struct clk_ops sam9x5_main_ops = {
  4825. @@ -558,18 +530,17 @@
  4826. };
  4827. static struct clk * __init
  4828. -at91_clk_register_sam9x5_main(struct at91_pmc *pmc,
  4829. - unsigned int irq,
  4830. +at91_clk_register_sam9x5_main(struct regmap *regmap,
  4831. const char *name,
  4832. const char **parent_names,
  4833. int num_parents)
  4834. {
  4835. - int ret;
  4836. struct clk_sam9x5_main *clkmain;
  4837. struct clk *clk = NULL;
  4838. struct clk_init_data init;
  4839. + unsigned int status;
  4840. - if (!pmc || !irq || !name)
  4841. + if (!name)
  4842. return ERR_PTR(-EINVAL);
  4843. if (!parent_names || !num_parents)
  4844. @@ -586,51 +557,42 @@
  4845. init.flags = CLK_SET_PARENT_GATE;
  4846. clkmain->hw.init = &init;
  4847. - clkmain->pmc = pmc;
  4848. - clkmain->irq = irq;
  4849. - clkmain->parent = !!(pmc_read(clkmain->pmc, AT91_CKGR_MOR) &
  4850. - AT91_PMC_MOSCEN);
  4851. - init_waitqueue_head(&clkmain->wait);
  4852. - irq_set_status_flags(clkmain->irq, IRQ_NOAUTOEN);
  4853. - ret = request_irq(clkmain->irq, clk_sam9x5_main_irq_handler,
  4854. - IRQF_TRIGGER_HIGH, name, clkmain);
  4855. - if (ret)
  4856. - return ERR_PTR(ret);
  4857. + clkmain->regmap = regmap;
  4858. + regmap_read(clkmain->regmap, AT91_CKGR_MOR, &status);
  4859. + clkmain->parent = status & AT91_PMC_MOSCEN ? 1 : 0;
  4860. clk = clk_register(NULL, &clkmain->hw);
  4861. - if (IS_ERR(clk)) {
  4862. - free_irq(clkmain->irq, clkmain);
  4863. + if (IS_ERR(clk))
  4864. kfree(clkmain);
  4865. - }
  4866. return clk;
  4867. }
  4868. -void __init of_at91sam9x5_clk_main_setup(struct device_node *np,
  4869. - struct at91_pmc *pmc)
  4870. +static void __init of_at91sam9x5_clk_main_setup(struct device_node *np)
  4871. {
  4872. struct clk *clk;
  4873. const char *parent_names[2];
  4874. int num_parents;
  4875. - unsigned int irq;
  4876. const char *name = np->name;
  4877. + struct regmap *regmap;
  4878. num_parents = of_clk_get_parent_count(np);
  4879. if (num_parents <= 0 || num_parents > 2)
  4880. return;
  4881. of_clk_parent_fill(np, parent_names, num_parents);
  4882. + regmap = syscon_node_to_regmap(of_get_parent(np));
  4883. + if (IS_ERR(regmap))
  4884. + return;
  4885. of_property_read_string(np, "clock-output-names", &name);
  4886. - irq = irq_of_parse_and_map(np, 0);
  4887. - if (!irq)
  4888. - return;
  4889. -
  4890. - clk = at91_clk_register_sam9x5_main(pmc, irq, name, parent_names,
  4891. + clk = at91_clk_register_sam9x5_main(regmap, name, parent_names,
  4892. num_parents);
  4893. if (IS_ERR(clk))
  4894. return;
  4895. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  4896. }
  4897. +CLK_OF_DECLARE(at91sam9x5_clk_main, "atmel,at91sam9x5-clk-main",
  4898. + of_at91sam9x5_clk_main_setup);
  4899. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-master.c linux-4.4.13/drivers/clk/at91/clk-master.c
  4900. --- linux-4.4.13.orig/drivers/clk/at91/clk-master.c 2016-06-08 03:14:51.000000000 +0200
  4901. +++ linux-4.4.13/drivers/clk/at91/clk-master.c 2016-06-22 21:55:07.998523867 +0200
  4902. @@ -12,13 +12,8 @@
  4903. #include <linux/clkdev.h>
  4904. #include <linux/clk/at91_pmc.h>
  4905. #include <linux/of.h>
  4906. -#include <linux/of_address.h>
  4907. -#include <linux/of_irq.h>
  4908. -#include <linux/io.h>
  4909. -#include <linux/wait.h>
  4910. -#include <linux/sched.h>
  4911. -#include <linux/interrupt.h>
  4912. -#include <linux/irq.h>
  4913. +#include <linux/mfd/syscon.h>
  4914. +#include <linux/regmap.h>
  4915. #include "pmc.h"
  4916. @@ -44,32 +39,26 @@
  4917. struct clk_master {
  4918. struct clk_hw hw;
  4919. - struct at91_pmc *pmc;
  4920. - unsigned int irq;
  4921. - wait_queue_head_t wait;
  4922. + struct regmap *regmap;
  4923. const struct clk_master_layout *layout;
  4924. const struct clk_master_characteristics *characteristics;
  4925. };
  4926. -static irqreturn_t clk_master_irq_handler(int irq, void *dev_id)
  4927. +static inline bool clk_master_ready(struct regmap *regmap)
  4928. {
  4929. - struct clk_master *master = (struct clk_master *)dev_id;
  4930. + unsigned int status;
  4931. - wake_up(&master->wait);
  4932. - disable_irq_nosync(master->irq);
  4933. + regmap_read(regmap, AT91_PMC_SR, &status);
  4934. - return IRQ_HANDLED;
  4935. + return status & AT91_PMC_MCKRDY ? 1 : 0;
  4936. }
  4937. +
  4938. static int clk_master_prepare(struct clk_hw *hw)
  4939. {
  4940. struct clk_master *master = to_clk_master(hw);
  4941. - struct at91_pmc *pmc = master->pmc;
  4942. - while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MCKRDY)) {
  4943. - enable_irq(master->irq);
  4944. - wait_event(master->wait,
  4945. - pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_MCKRDY);
  4946. - }
  4947. + while (!clk_master_ready(master->regmap))
  4948. + cpu_relax();
  4949. return 0;
  4950. }
  4951. @@ -78,7 +67,7 @@
  4952. {
  4953. struct clk_master *master = to_clk_master(hw);
  4954. - return !!(pmc_read(master->pmc, AT91_PMC_SR) & AT91_PMC_MCKRDY);
  4955. + return clk_master_ready(master->regmap);
  4956. }
  4957. static unsigned long clk_master_recalc_rate(struct clk_hw *hw,
  4958. @@ -88,18 +77,16 @@
  4959. u8 div;
  4960. unsigned long rate = parent_rate;
  4961. struct clk_master *master = to_clk_master(hw);
  4962. - struct at91_pmc *pmc = master->pmc;
  4963. const struct clk_master_layout *layout = master->layout;
  4964. const struct clk_master_characteristics *characteristics =
  4965. master->characteristics;
  4966. - u32 tmp;
  4967. + unsigned int mckr;
  4968. - pmc_lock(pmc);
  4969. - tmp = pmc_read(pmc, AT91_PMC_MCKR) & layout->mask;
  4970. - pmc_unlock(pmc);
  4971. + regmap_read(master->regmap, AT91_PMC_MCKR, &mckr);
  4972. + mckr &= layout->mask;
  4973. - pres = (tmp >> layout->pres_shift) & MASTER_PRES_MASK;
  4974. - div = (tmp >> MASTER_DIV_SHIFT) & MASTER_DIV_MASK;
  4975. + pres = (mckr >> layout->pres_shift) & MASTER_PRES_MASK;
  4976. + div = (mckr >> MASTER_DIV_SHIFT) & MASTER_DIV_MASK;
  4977. if (characteristics->have_div3_pres && pres == MASTER_PRES_MAX)
  4978. rate /= 3;
  4979. @@ -119,9 +106,11 @@
  4980. static u8 clk_master_get_parent(struct clk_hw *hw)
  4981. {
  4982. struct clk_master *master = to_clk_master(hw);
  4983. - struct at91_pmc *pmc = master->pmc;
  4984. + unsigned int mckr;
  4985. - return pmc_read(pmc, AT91_PMC_MCKR) & AT91_PMC_CSS;
  4986. + regmap_read(master->regmap, AT91_PMC_MCKR, &mckr);
  4987. +
  4988. + return mckr & AT91_PMC_CSS;
  4989. }
  4990. static const struct clk_ops master_ops = {
  4991. @@ -132,18 +121,17 @@
  4992. };
  4993. static struct clk * __init
  4994. -at91_clk_register_master(struct at91_pmc *pmc, unsigned int irq,
  4995. +at91_clk_register_master(struct regmap *regmap,
  4996. const char *name, int num_parents,
  4997. const char **parent_names,
  4998. const struct clk_master_layout *layout,
  4999. const struct clk_master_characteristics *characteristics)
  5000. {
  5001. - int ret;
  5002. struct clk_master *master;
  5003. struct clk *clk = NULL;
  5004. struct clk_init_data init;
  5005. - if (!pmc || !irq || !name || !num_parents || !parent_names)
  5006. + if (!name || !num_parents || !parent_names)
  5007. return ERR_PTR(-EINVAL);
  5008. master = kzalloc(sizeof(*master), GFP_KERNEL);
  5009. @@ -159,20 +147,10 @@
  5010. master->hw.init = &init;
  5011. master->layout = layout;
  5012. master->characteristics = characteristics;
  5013. - master->pmc = pmc;
  5014. - master->irq = irq;
  5015. - init_waitqueue_head(&master->wait);
  5016. - irq_set_status_flags(master->irq, IRQ_NOAUTOEN);
  5017. - ret = request_irq(master->irq, clk_master_irq_handler,
  5018. - IRQF_TRIGGER_HIGH, "clk-master", master);
  5019. - if (ret) {
  5020. - kfree(master);
  5021. - return ERR_PTR(ret);
  5022. - }
  5023. + master->regmap = regmap;
  5024. clk = clk_register(NULL, &master->hw);
  5025. if (IS_ERR(clk)) {
  5026. - free_irq(master->irq, master);
  5027. kfree(master);
  5028. }
  5029. @@ -217,15 +195,15 @@
  5030. }
  5031. static void __init
  5032. -of_at91_clk_master_setup(struct device_node *np, struct at91_pmc *pmc,
  5033. +of_at91_clk_master_setup(struct device_node *np,
  5034. const struct clk_master_layout *layout)
  5035. {
  5036. struct clk *clk;
  5037. int num_parents;
  5038. - unsigned int irq;
  5039. const char *parent_names[MASTER_SOURCE_MAX];
  5040. const char *name = np->name;
  5041. struct clk_master_characteristics *characteristics;
  5042. + struct regmap *regmap;
  5043. num_parents = of_clk_get_parent_count(np);
  5044. if (num_parents <= 0 || num_parents > MASTER_SOURCE_MAX)
  5045. @@ -239,11 +217,11 @@
  5046. if (!characteristics)
  5047. return;
  5048. - irq = irq_of_parse_and_map(np, 0);
  5049. - if (!irq)
  5050. - goto out_free_characteristics;
  5051. + regmap = syscon_node_to_regmap(of_get_parent(np));
  5052. + if (IS_ERR(regmap))
  5053. + return;
  5054. - clk = at91_clk_register_master(pmc, irq, name, num_parents,
  5055. + clk = at91_clk_register_master(regmap, name, num_parents,
  5056. parent_names, layout,
  5057. characteristics);
  5058. if (IS_ERR(clk))
  5059. @@ -256,14 +234,16 @@
  5060. kfree(characteristics);
  5061. }
  5062. -void __init of_at91rm9200_clk_master_setup(struct device_node *np,
  5063. - struct at91_pmc *pmc)
  5064. +static void __init of_at91rm9200_clk_master_setup(struct device_node *np)
  5065. {
  5066. - of_at91_clk_master_setup(np, pmc, &at91rm9200_master_layout);
  5067. + of_at91_clk_master_setup(np, &at91rm9200_master_layout);
  5068. }
  5069. +CLK_OF_DECLARE(at91rm9200_clk_master, "atmel,at91rm9200-clk-master",
  5070. + of_at91rm9200_clk_master_setup);
  5071. -void __init of_at91sam9x5_clk_master_setup(struct device_node *np,
  5072. - struct at91_pmc *pmc)
  5073. +static void __init of_at91sam9x5_clk_master_setup(struct device_node *np)
  5074. {
  5075. - of_at91_clk_master_setup(np, pmc, &at91sam9x5_master_layout);
  5076. + of_at91_clk_master_setup(np, &at91sam9x5_master_layout);
  5077. }
  5078. +CLK_OF_DECLARE(at91sam9x5_clk_master, "atmel,at91sam9x5-clk-master",
  5079. + of_at91sam9x5_clk_master_setup);
  5080. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-peripheral.c linux-4.4.13/drivers/clk/at91/clk-peripheral.c
  5081. --- linux-4.4.13.orig/drivers/clk/at91/clk-peripheral.c 2016-06-08 03:14:51.000000000 +0200
  5082. +++ linux-4.4.13/drivers/clk/at91/clk-peripheral.c 2016-06-22 21:55:07.998523867 +0200
  5083. @@ -12,11 +12,13 @@
  5084. #include <linux/clkdev.h>
  5085. #include <linux/clk/at91_pmc.h>
  5086. #include <linux/of.h>
  5087. -#include <linux/of_address.h>
  5088. -#include <linux/io.h>
  5089. +#include <linux/mfd/syscon.h>
  5090. +#include <linux/regmap.h>
  5091. #include "pmc.h"
  5092. +DEFINE_SPINLOCK(pmc_pcr_lock);
  5093. +
  5094. #define PERIPHERAL_MAX 64
  5095. #define PERIPHERAL_AT91RM9200 0
  5096. @@ -33,7 +35,7 @@
  5097. struct clk_peripheral {
  5098. struct clk_hw hw;
  5099. - struct at91_pmc *pmc;
  5100. + struct regmap *regmap;
  5101. u32 id;
  5102. };
  5103. @@ -41,8 +43,9 @@
  5104. struct clk_sam9x5_peripheral {
  5105. struct clk_hw hw;
  5106. - struct at91_pmc *pmc;
  5107. + struct regmap *regmap;
  5108. struct clk_range range;
  5109. + spinlock_t *lock;
  5110. u32 id;
  5111. u32 div;
  5112. bool auto_div;
  5113. @@ -54,7 +57,6 @@
  5114. static int clk_peripheral_enable(struct clk_hw *hw)
  5115. {
  5116. struct clk_peripheral *periph = to_clk_peripheral(hw);
  5117. - struct at91_pmc *pmc = periph->pmc;
  5118. int offset = AT91_PMC_PCER;
  5119. u32 id = periph->id;
  5120. @@ -62,14 +64,14 @@
  5121. return 0;
  5122. if (id > PERIPHERAL_ID_MAX)
  5123. offset = AT91_PMC_PCER1;
  5124. - pmc_write(pmc, offset, PERIPHERAL_MASK(id));
  5125. + regmap_write(periph->regmap, offset, PERIPHERAL_MASK(id));
  5126. +
  5127. return 0;
  5128. }
  5129. static void clk_peripheral_disable(struct clk_hw *hw)
  5130. {
  5131. struct clk_peripheral *periph = to_clk_peripheral(hw);
  5132. - struct at91_pmc *pmc = periph->pmc;
  5133. int offset = AT91_PMC_PCDR;
  5134. u32 id = periph->id;
  5135. @@ -77,21 +79,23 @@
  5136. return;
  5137. if (id > PERIPHERAL_ID_MAX)
  5138. offset = AT91_PMC_PCDR1;
  5139. - pmc_write(pmc, offset, PERIPHERAL_MASK(id));
  5140. + regmap_write(periph->regmap, offset, PERIPHERAL_MASK(id));
  5141. }
  5142. static int clk_peripheral_is_enabled(struct clk_hw *hw)
  5143. {
  5144. struct clk_peripheral *periph = to_clk_peripheral(hw);
  5145. - struct at91_pmc *pmc = periph->pmc;
  5146. int offset = AT91_PMC_PCSR;
  5147. + unsigned int status;
  5148. u32 id = periph->id;
  5149. if (id < PERIPHERAL_ID_MIN)
  5150. return 1;
  5151. if (id > PERIPHERAL_ID_MAX)
  5152. offset = AT91_PMC_PCSR1;
  5153. - return !!(pmc_read(pmc, offset) & PERIPHERAL_MASK(id));
  5154. + regmap_read(periph->regmap, offset, &status);
  5155. +
  5156. + return status & PERIPHERAL_MASK(id) ? 1 : 0;
  5157. }
  5158. static const struct clk_ops peripheral_ops = {
  5159. @@ -101,14 +105,14 @@
  5160. };
  5161. static struct clk * __init
  5162. -at91_clk_register_peripheral(struct at91_pmc *pmc, const char *name,
  5163. +at91_clk_register_peripheral(struct regmap *regmap, const char *name,
  5164. const char *parent_name, u32 id)
  5165. {
  5166. struct clk_peripheral *periph;
  5167. struct clk *clk = NULL;
  5168. struct clk_init_data init;
  5169. - if (!pmc || !name || !parent_name || id > PERIPHERAL_ID_MAX)
  5170. + if (!name || !parent_name || id > PERIPHERAL_ID_MAX)
  5171. return ERR_PTR(-EINVAL);
  5172. periph = kzalloc(sizeof(*periph), GFP_KERNEL);
  5173. @@ -123,7 +127,7 @@
  5174. periph->id = id;
  5175. periph->hw.init = &init;
  5176. - periph->pmc = pmc;
  5177. + periph->regmap = regmap;
  5178. clk = clk_register(NULL, &periph->hw);
  5179. if (IS_ERR(clk))
  5180. @@ -160,53 +164,58 @@
  5181. static int clk_sam9x5_peripheral_enable(struct clk_hw *hw)
  5182. {
  5183. struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
  5184. - struct at91_pmc *pmc = periph->pmc;
  5185. - u32 tmp;
  5186. + unsigned long flags;
  5187. if (periph->id < PERIPHERAL_ID_MIN)
  5188. return 0;
  5189. - pmc_lock(pmc);
  5190. - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
  5191. - tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_DIV_MASK;
  5192. - pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_DIV(periph->div)
  5193. - | AT91_PMC_PCR_CMD
  5194. - | AT91_PMC_PCR_EN);
  5195. - pmc_unlock(pmc);
  5196. + spin_lock_irqsave(periph->lock, flags);
  5197. + regmap_write(periph->regmap, AT91_PMC_PCR,
  5198. + (periph->id & AT91_PMC_PCR_PID_MASK));
  5199. + regmap_update_bits(periph->regmap, AT91_PMC_PCR,
  5200. + AT91_PMC_PCR_DIV_MASK | AT91_PMC_PCR_CMD |
  5201. + AT91_PMC_PCR_EN,
  5202. + AT91_PMC_PCR_DIV(periph->div) |
  5203. + AT91_PMC_PCR_CMD |
  5204. + AT91_PMC_PCR_EN);
  5205. + spin_unlock_irqrestore(periph->lock, flags);
  5206. +
  5207. return 0;
  5208. }
  5209. static void clk_sam9x5_peripheral_disable(struct clk_hw *hw)
  5210. {
  5211. struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
  5212. - struct at91_pmc *pmc = periph->pmc;
  5213. - u32 tmp;
  5214. + unsigned long flags;
  5215. if (periph->id < PERIPHERAL_ID_MIN)
  5216. return;
  5217. - pmc_lock(pmc);
  5218. - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
  5219. - tmp = pmc_read(pmc, AT91_PMC_PCR) & ~AT91_PMC_PCR_EN;
  5220. - pmc_write(pmc, AT91_PMC_PCR, tmp | AT91_PMC_PCR_CMD);
  5221. - pmc_unlock(pmc);
  5222. + spin_lock_irqsave(periph->lock, flags);
  5223. + regmap_write(periph->regmap, AT91_PMC_PCR,
  5224. + (periph->id & AT91_PMC_PCR_PID_MASK));
  5225. + regmap_update_bits(periph->regmap, AT91_PMC_PCR,
  5226. + AT91_PMC_PCR_EN | AT91_PMC_PCR_CMD,
  5227. + AT91_PMC_PCR_CMD);
  5228. + spin_unlock_irqrestore(periph->lock, flags);
  5229. }
  5230. static int clk_sam9x5_peripheral_is_enabled(struct clk_hw *hw)
  5231. {
  5232. struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
  5233. - struct at91_pmc *pmc = periph->pmc;
  5234. - int ret;
  5235. + unsigned long flags;
  5236. + unsigned int status;
  5237. if (periph->id < PERIPHERAL_ID_MIN)
  5238. return 1;
  5239. - pmc_lock(pmc);
  5240. - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
  5241. - ret = !!(pmc_read(pmc, AT91_PMC_PCR) & AT91_PMC_PCR_EN);
  5242. - pmc_unlock(pmc);
  5243. + spin_lock_irqsave(periph->lock, flags);
  5244. + regmap_write(periph->regmap, AT91_PMC_PCR,
  5245. + (periph->id & AT91_PMC_PCR_PID_MASK));
  5246. + regmap_read(periph->regmap, AT91_PMC_PCR, &status);
  5247. + spin_unlock_irqrestore(periph->lock, flags);
  5248. - return ret;
  5249. + return status & AT91_PMC_PCR_EN ? 1 : 0;
  5250. }
  5251. static unsigned long
  5252. @@ -214,19 +223,20 @@
  5253. unsigned long parent_rate)
  5254. {
  5255. struct clk_sam9x5_peripheral *periph = to_clk_sam9x5_peripheral(hw);
  5256. - struct at91_pmc *pmc = periph->pmc;
  5257. - u32 tmp;
  5258. + unsigned long flags;
  5259. + unsigned int status;
  5260. if (periph->id < PERIPHERAL_ID_MIN)
  5261. return parent_rate;
  5262. - pmc_lock(pmc);
  5263. - pmc_write(pmc, AT91_PMC_PCR, (periph->id & AT91_PMC_PCR_PID_MASK));
  5264. - tmp = pmc_read(pmc, AT91_PMC_PCR);
  5265. - pmc_unlock(pmc);
  5266. + spin_lock_irqsave(periph->lock, flags);
  5267. + regmap_write(periph->regmap, AT91_PMC_PCR,
  5268. + (periph->id & AT91_PMC_PCR_PID_MASK));
  5269. + regmap_read(periph->regmap, AT91_PMC_PCR, &status);
  5270. + spin_unlock_irqrestore(periph->lock, flags);
  5271. - if (tmp & AT91_PMC_PCR_EN) {
  5272. - periph->div = PERIPHERAL_RSHIFT(tmp);
  5273. + if (status & AT91_PMC_PCR_EN) {
  5274. + periph->div = PERIPHERAL_RSHIFT(status);
  5275. periph->auto_div = false;
  5276. } else {
  5277. clk_sam9x5_peripheral_autodiv(periph);
  5278. @@ -318,15 +328,15 @@
  5279. };
  5280. static struct clk * __init
  5281. -at91_clk_register_sam9x5_peripheral(struct at91_pmc *pmc, const char *name,
  5282. - const char *parent_name, u32 id,
  5283. - const struct clk_range *range)
  5284. +at91_clk_register_sam9x5_peripheral(struct regmap *regmap, spinlock_t *lock,
  5285. + const char *name, const char *parent_name,
  5286. + u32 id, const struct clk_range *range)
  5287. {
  5288. struct clk_sam9x5_peripheral *periph;
  5289. struct clk *clk = NULL;
  5290. struct clk_init_data init;
  5291. - if (!pmc || !name || !parent_name)
  5292. + if (!name || !parent_name)
  5293. return ERR_PTR(-EINVAL);
  5294. periph = kzalloc(sizeof(*periph), GFP_KERNEL);
  5295. @@ -342,7 +352,8 @@
  5296. periph->id = id;
  5297. periph->hw.init = &init;
  5298. periph->div = 0;
  5299. - periph->pmc = pmc;
  5300. + periph->regmap = regmap;
  5301. + periph->lock = lock;
  5302. periph->auto_div = true;
  5303. periph->range = *range;
  5304. @@ -356,7 +367,7 @@
  5305. }
  5306. static void __init
  5307. -of_at91_clk_periph_setup(struct device_node *np, struct at91_pmc *pmc, u8 type)
  5308. +of_at91_clk_periph_setup(struct device_node *np, u8 type)
  5309. {
  5310. int num;
  5311. u32 id;
  5312. @@ -364,6 +375,7 @@
  5313. const char *parent_name;
  5314. const char *name;
  5315. struct device_node *periphclknp;
  5316. + struct regmap *regmap;
  5317. parent_name = of_clk_get_parent_name(np, 0);
  5318. if (!parent_name)
  5319. @@ -373,6 +385,10 @@
  5320. if (!num || num > PERIPHERAL_MAX)
  5321. return;
  5322. + regmap = syscon_node_to_regmap(of_get_parent(np));
  5323. + if (IS_ERR(regmap))
  5324. + return;
  5325. +
  5326. for_each_child_of_node(np, periphclknp) {
  5327. if (of_property_read_u32(periphclknp, "reg", &id))
  5328. continue;
  5329. @@ -384,7 +400,7 @@
  5330. name = periphclknp->name;
  5331. if (type == PERIPHERAL_AT91RM9200) {
  5332. - clk = at91_clk_register_peripheral(pmc, name,
  5333. + clk = at91_clk_register_peripheral(regmap, name,
  5334. parent_name, id);
  5335. } else {
  5336. struct clk_range range = CLK_RANGE(0, 0);
  5337. @@ -393,7 +409,9 @@
  5338. "atmel,clk-output-range",
  5339. &range);
  5340. - clk = at91_clk_register_sam9x5_peripheral(pmc, name,
  5341. + clk = at91_clk_register_sam9x5_peripheral(regmap,
  5342. + &pmc_pcr_lock,
  5343. + name,
  5344. parent_name,
  5345. id, &range);
  5346. }
  5347. @@ -405,14 +423,16 @@
  5348. }
  5349. }
  5350. -void __init of_at91rm9200_clk_periph_setup(struct device_node *np,
  5351. - struct at91_pmc *pmc)
  5352. +static void __init of_at91rm9200_clk_periph_setup(struct device_node *np)
  5353. {
  5354. - of_at91_clk_periph_setup(np, pmc, PERIPHERAL_AT91RM9200);
  5355. + of_at91_clk_periph_setup(np, PERIPHERAL_AT91RM9200);
  5356. }
  5357. +CLK_OF_DECLARE(at91rm9200_clk_periph, "atmel,at91rm9200-clk-peripheral",
  5358. + of_at91rm9200_clk_periph_setup);
  5359. -void __init of_at91sam9x5_clk_periph_setup(struct device_node *np,
  5360. - struct at91_pmc *pmc)
  5361. +static void __init of_at91sam9x5_clk_periph_setup(struct device_node *np)
  5362. {
  5363. - of_at91_clk_periph_setup(np, pmc, PERIPHERAL_AT91SAM9X5);
  5364. + of_at91_clk_periph_setup(np, PERIPHERAL_AT91SAM9X5);
  5365. }
  5366. +CLK_OF_DECLARE(at91sam9x5_clk_periph, "atmel,at91sam9x5-clk-peripheral",
  5367. + of_at91sam9x5_clk_periph_setup);
  5368. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-pll.c linux-4.4.13/drivers/clk/at91/clk-pll.c
  5369. --- linux-4.4.13.orig/drivers/clk/at91/clk-pll.c 2016-06-08 03:14:51.000000000 +0200
  5370. +++ linux-4.4.13/drivers/clk/at91/clk-pll.c 2016-06-22 21:55:07.998523867 +0200
  5371. @@ -12,14 +12,8 @@
  5372. #include <linux/clkdev.h>
  5373. #include <linux/clk/at91_pmc.h>
  5374. #include <linux/of.h>
  5375. -#include <linux/of_address.h>
  5376. -#include <linux/of_irq.h>
  5377. -#include <linux/io.h>
  5378. -#include <linux/kernel.h>
  5379. -#include <linux/wait.h>
  5380. -#include <linux/sched.h>
  5381. -#include <linux/interrupt.h>
  5382. -#include <linux/irq.h>
  5383. +#include <linux/mfd/syscon.h>
  5384. +#include <linux/regmap.h>
  5385. #include "pmc.h"
  5386. @@ -58,9 +52,7 @@
  5387. struct clk_pll {
  5388. struct clk_hw hw;
  5389. - struct at91_pmc *pmc;
  5390. - unsigned int irq;
  5391. - wait_queue_head_t wait;
  5392. + struct regmap *regmap;
  5393. u8 id;
  5394. u8 div;
  5395. u8 range;
  5396. @@ -69,20 +61,19 @@
  5397. const struct clk_pll_characteristics *characteristics;
  5398. };
  5399. -static irqreturn_t clk_pll_irq_handler(int irq, void *dev_id)
  5400. +static inline bool clk_pll_ready(struct regmap *regmap, int id)
  5401. {
  5402. - struct clk_pll *pll = (struct clk_pll *)dev_id;
  5403. + unsigned int status;
  5404. - wake_up(&pll->wait);
  5405. - disable_irq_nosync(pll->irq);
  5406. + regmap_read(regmap, AT91_PMC_SR, &status);
  5407. - return IRQ_HANDLED;
  5408. + return status & PLL_STATUS_MASK(id) ? 1 : 0;
  5409. }
  5410. static int clk_pll_prepare(struct clk_hw *hw)
  5411. {
  5412. struct clk_pll *pll = to_clk_pll(hw);
  5413. - struct at91_pmc *pmc = pll->pmc;
  5414. + struct regmap *regmap = pll->regmap;
  5415. const struct clk_pll_layout *layout = pll->layout;
  5416. const struct clk_pll_characteristics *characteristics =
  5417. pll->characteristics;
  5418. @@ -90,39 +81,34 @@
  5419. u32 mask = PLL_STATUS_MASK(id);
  5420. int offset = PLL_REG(id);
  5421. u8 out = 0;
  5422. - u32 pllr, icpr;
  5423. + unsigned int pllr;
  5424. + unsigned int status;
  5425. u8 div;
  5426. u16 mul;
  5427. - pllr = pmc_read(pmc, offset);
  5428. + regmap_read(regmap, offset, &pllr);
  5429. div = PLL_DIV(pllr);
  5430. mul = PLL_MUL(pllr, layout);
  5431. - if ((pmc_read(pmc, AT91_PMC_SR) & mask) &&
  5432. + regmap_read(regmap, AT91_PMC_SR, &status);
  5433. + if ((status & mask) &&
  5434. (div == pll->div && mul == pll->mul))
  5435. return 0;
  5436. if (characteristics->out)
  5437. out = characteristics->out[pll->range];
  5438. - if (characteristics->icpll) {
  5439. - icpr = pmc_read(pmc, AT91_PMC_PLLICPR) & ~PLL_ICPR_MASK(id);
  5440. - icpr |= (characteristics->icpll[pll->range] <<
  5441. - PLL_ICPR_SHIFT(id));
  5442. - pmc_write(pmc, AT91_PMC_PLLICPR, icpr);
  5443. - }
  5444. - pllr &= ~layout->pllr_mask;
  5445. - pllr |= layout->pllr_mask &
  5446. - (pll->div | (PLL_MAX_COUNT << PLL_COUNT_SHIFT) |
  5447. - (out << PLL_OUT_SHIFT) |
  5448. - ((pll->mul & layout->mul_mask) << layout->mul_shift));
  5449. - pmc_write(pmc, offset, pllr);
  5450. -
  5451. - while (!(pmc_read(pmc, AT91_PMC_SR) & mask)) {
  5452. - enable_irq(pll->irq);
  5453. - wait_event(pll->wait,
  5454. - pmc_read(pmc, AT91_PMC_SR) & mask);
  5455. - }
  5456. + if (characteristics->icpll)
  5457. + regmap_update_bits(regmap, AT91_PMC_PLLICPR, PLL_ICPR_MASK(id),
  5458. + characteristics->icpll[pll->range] << PLL_ICPR_SHIFT(id));
  5459. +
  5460. + regmap_update_bits(regmap, offset, layout->pllr_mask,
  5461. + pll->div | (PLL_MAX_COUNT << PLL_COUNT_SHIFT) |
  5462. + (out << PLL_OUT_SHIFT) |
  5463. + ((pll->mul & layout->mul_mask) << layout->mul_shift));
  5464. +
  5465. + while (!clk_pll_ready(regmap, pll->id))
  5466. + cpu_relax();
  5467. return 0;
  5468. }
  5469. @@ -130,32 +116,35 @@
  5470. static int clk_pll_is_prepared(struct clk_hw *hw)
  5471. {
  5472. struct clk_pll *pll = to_clk_pll(hw);
  5473. - struct at91_pmc *pmc = pll->pmc;
  5474. - return !!(pmc_read(pmc, AT91_PMC_SR) &
  5475. - PLL_STATUS_MASK(pll->id));
  5476. + return clk_pll_ready(pll->regmap, pll->id);
  5477. }
  5478. static void clk_pll_unprepare(struct clk_hw *hw)
  5479. {
  5480. struct clk_pll *pll = to_clk_pll(hw);
  5481. - struct at91_pmc *pmc = pll->pmc;
  5482. - const struct clk_pll_layout *layout = pll->layout;
  5483. - int offset = PLL_REG(pll->id);
  5484. - u32 tmp = pmc_read(pmc, offset) & ~(layout->pllr_mask);
  5485. + unsigned int mask = pll->layout->pllr_mask;
  5486. - pmc_write(pmc, offset, tmp);
  5487. + regmap_update_bits(pll->regmap, PLL_REG(pll->id), mask, ~mask);
  5488. }
  5489. static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
  5490. unsigned long parent_rate)
  5491. {
  5492. struct clk_pll *pll = to_clk_pll(hw);
  5493. + unsigned int pllr;
  5494. + u16 mul;
  5495. + u8 div;
  5496. +
  5497. + regmap_read(pll->regmap, PLL_REG(pll->id), &pllr);
  5498. +
  5499. + div = PLL_DIV(pllr);
  5500. + mul = PLL_MUL(pllr, pll->layout);
  5501. - if (!pll->div || !pll->mul)
  5502. + if (!div || !mul)
  5503. return 0;
  5504. - return (parent_rate / pll->div) * (pll->mul + 1);
  5505. + return (parent_rate / div) * (mul + 1);
  5506. }
  5507. static long clk_pll_get_best_div_mul(struct clk_pll *pll, unsigned long rate,
  5508. @@ -308,7 +297,7 @@
  5509. };
  5510. static struct clk * __init
  5511. -at91_clk_register_pll(struct at91_pmc *pmc, unsigned int irq, const char *name,
  5512. +at91_clk_register_pll(struct regmap *regmap, const char *name,
  5513. const char *parent_name, u8 id,
  5514. const struct clk_pll_layout *layout,
  5515. const struct clk_pll_characteristics *characteristics)
  5516. @@ -316,9 +305,8 @@
  5517. struct clk_pll *pll;
  5518. struct clk *clk = NULL;
  5519. struct clk_init_data init;
  5520. - int ret;
  5521. int offset = PLL_REG(id);
  5522. - u32 tmp;
  5523. + unsigned int pllr;
  5524. if (id > PLL_MAX_ID)
  5525. return ERR_PTR(-EINVAL);
  5526. @@ -337,23 +325,13 @@
  5527. pll->hw.init = &init;
  5528. pll->layout = layout;
  5529. pll->characteristics = characteristics;
  5530. - pll->pmc = pmc;
  5531. - pll->irq = irq;
  5532. - tmp = pmc_read(pmc, offset) & layout->pllr_mask;
  5533. - pll->div = PLL_DIV(tmp);
  5534. - pll->mul = PLL_MUL(tmp, layout);
  5535. - init_waitqueue_head(&pll->wait);
  5536. - irq_set_status_flags(pll->irq, IRQ_NOAUTOEN);
  5537. - ret = request_irq(pll->irq, clk_pll_irq_handler, IRQF_TRIGGER_HIGH,
  5538. - id ? "clk-pllb" : "clk-plla", pll);
  5539. - if (ret) {
  5540. - kfree(pll);
  5541. - return ERR_PTR(ret);
  5542. - }
  5543. + pll->regmap = regmap;
  5544. + regmap_read(regmap, offset, &pllr);
  5545. + pll->div = PLL_DIV(pllr);
  5546. + pll->mul = PLL_MUL(pllr, layout);
  5547. clk = clk_register(NULL, &pll->hw);
  5548. if (IS_ERR(clk)) {
  5549. - free_irq(pll->irq, pll);
  5550. kfree(pll);
  5551. }
  5552. @@ -483,12 +461,12 @@
  5553. }
  5554. static void __init
  5555. -of_at91_clk_pll_setup(struct device_node *np, struct at91_pmc *pmc,
  5556. +of_at91_clk_pll_setup(struct device_node *np,
  5557. const struct clk_pll_layout *layout)
  5558. {
  5559. u32 id;
  5560. - unsigned int irq;
  5561. struct clk *clk;
  5562. + struct regmap *regmap;
  5563. const char *parent_name;
  5564. const char *name = np->name;
  5565. struct clk_pll_characteristics *characteristics;
  5566. @@ -500,15 +478,15 @@
  5567. of_property_read_string(np, "clock-output-names", &name);
  5568. - characteristics = of_at91_clk_pll_get_characteristics(np);
  5569. - if (!characteristics)
  5570. + regmap = syscon_node_to_regmap(of_get_parent(np));
  5571. + if (IS_ERR(regmap))
  5572. return;
  5573. - irq = irq_of_parse_and_map(np, 0);
  5574. - if (!irq)
  5575. + characteristics = of_at91_clk_pll_get_characteristics(np);
  5576. + if (!characteristics)
  5577. return;
  5578. - clk = at91_clk_register_pll(pmc, irq, name, parent_name, id, layout,
  5579. + clk = at91_clk_register_pll(regmap, name, parent_name, id, layout,
  5580. characteristics);
  5581. if (IS_ERR(clk))
  5582. goto out_free_characteristics;
  5583. @@ -520,26 +498,30 @@
  5584. kfree(characteristics);
  5585. }
  5586. -void __init of_at91rm9200_clk_pll_setup(struct device_node *np,
  5587. - struct at91_pmc *pmc)
  5588. +static void __init of_at91rm9200_clk_pll_setup(struct device_node *np)
  5589. {
  5590. - of_at91_clk_pll_setup(np, pmc, &at91rm9200_pll_layout);
  5591. + of_at91_clk_pll_setup(np, &at91rm9200_pll_layout);
  5592. }
  5593. +CLK_OF_DECLARE(at91rm9200_clk_pll, "atmel,at91rm9200-clk-pll",
  5594. + of_at91rm9200_clk_pll_setup);
  5595. -void __init of_at91sam9g45_clk_pll_setup(struct device_node *np,
  5596. - struct at91_pmc *pmc)
  5597. +static void __init of_at91sam9g45_clk_pll_setup(struct device_node *np)
  5598. {
  5599. - of_at91_clk_pll_setup(np, pmc, &at91sam9g45_pll_layout);
  5600. + of_at91_clk_pll_setup(np, &at91sam9g45_pll_layout);
  5601. }
  5602. +CLK_OF_DECLARE(at91sam9g45_clk_pll, "atmel,at91sam9g45-clk-pll",
  5603. + of_at91sam9g45_clk_pll_setup);
  5604. -void __init of_at91sam9g20_clk_pllb_setup(struct device_node *np,
  5605. - struct at91_pmc *pmc)
  5606. +static void __init of_at91sam9g20_clk_pllb_setup(struct device_node *np)
  5607. {
  5608. - of_at91_clk_pll_setup(np, pmc, &at91sam9g20_pllb_layout);
  5609. + of_at91_clk_pll_setup(np, &at91sam9g20_pllb_layout);
  5610. }
  5611. +CLK_OF_DECLARE(at91sam9g20_clk_pllb, "atmel,at91sam9g20-clk-pllb",
  5612. + of_at91sam9g20_clk_pllb_setup);
  5613. -void __init of_sama5d3_clk_pll_setup(struct device_node *np,
  5614. - struct at91_pmc *pmc)
  5615. +static void __init of_sama5d3_clk_pll_setup(struct device_node *np)
  5616. {
  5617. - of_at91_clk_pll_setup(np, pmc, &sama5d3_pll_layout);
  5618. + of_at91_clk_pll_setup(np, &sama5d3_pll_layout);
  5619. }
  5620. +CLK_OF_DECLARE(sama5d3_clk_pll, "atmel,sama5d3-clk-pll",
  5621. + of_sama5d3_clk_pll_setup);
  5622. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-plldiv.c linux-4.4.13/drivers/clk/at91/clk-plldiv.c
  5623. --- linux-4.4.13.orig/drivers/clk/at91/clk-plldiv.c 2016-06-08 03:14:51.000000000 +0200
  5624. +++ linux-4.4.13/drivers/clk/at91/clk-plldiv.c 2016-06-22 21:55:07.998523867 +0200
  5625. @@ -12,8 +12,8 @@
  5626. #include <linux/clkdev.h>
  5627. #include <linux/clk/at91_pmc.h>
  5628. #include <linux/of.h>
  5629. -#include <linux/of_address.h>
  5630. -#include <linux/io.h>
  5631. +#include <linux/mfd/syscon.h>
  5632. +#include <linux/regmap.h>
  5633. #include "pmc.h"
  5634. @@ -21,16 +21,18 @@
  5635. struct clk_plldiv {
  5636. struct clk_hw hw;
  5637. - struct at91_pmc *pmc;
  5638. + struct regmap *regmap;
  5639. };
  5640. static unsigned long clk_plldiv_recalc_rate(struct clk_hw *hw,
  5641. unsigned long parent_rate)
  5642. {
  5643. struct clk_plldiv *plldiv = to_clk_plldiv(hw);
  5644. - struct at91_pmc *pmc = plldiv->pmc;
  5645. + unsigned int mckr;
  5646. - if (pmc_read(pmc, AT91_PMC_MCKR) & AT91_PMC_PLLADIV2)
  5647. + regmap_read(plldiv->regmap, AT91_PMC_MCKR, &mckr);
  5648. +
  5649. + if (mckr & AT91_PMC_PLLADIV2)
  5650. return parent_rate / 2;
  5651. return parent_rate;
  5652. @@ -57,18 +59,12 @@
  5653. unsigned long parent_rate)
  5654. {
  5655. struct clk_plldiv *plldiv = to_clk_plldiv(hw);
  5656. - struct at91_pmc *pmc = plldiv->pmc;
  5657. - u32 tmp;
  5658. - if (parent_rate != rate && (parent_rate / 2) != rate)
  5659. + if ((parent_rate != rate) && (parent_rate / 2 != rate))
  5660. return -EINVAL;
  5661. - pmc_lock(pmc);
  5662. - tmp = pmc_read(pmc, AT91_PMC_MCKR) & ~AT91_PMC_PLLADIV2;
  5663. - if ((parent_rate / 2) == rate)
  5664. - tmp |= AT91_PMC_PLLADIV2;
  5665. - pmc_write(pmc, AT91_PMC_MCKR, tmp);
  5666. - pmc_unlock(pmc);
  5667. + regmap_update_bits(plldiv->regmap, AT91_PMC_MCKR, AT91_PMC_PLLADIV2,
  5668. + parent_rate != rate ? AT91_PMC_PLLADIV2 : 0);
  5669. return 0;
  5670. }
  5671. @@ -80,7 +76,7 @@
  5672. };
  5673. static struct clk * __init
  5674. -at91_clk_register_plldiv(struct at91_pmc *pmc, const char *name,
  5675. +at91_clk_register_plldiv(struct regmap *regmap, const char *name,
  5676. const char *parent_name)
  5677. {
  5678. struct clk_plldiv *plldiv;
  5679. @@ -98,7 +94,7 @@
  5680. init.flags = CLK_SET_RATE_GATE;
  5681. plldiv->hw.init = &init;
  5682. - plldiv->pmc = pmc;
  5683. + plldiv->regmap = regmap;
  5684. clk = clk_register(NULL, &plldiv->hw);
  5685. @@ -109,27 +105,27 @@
  5686. }
  5687. static void __init
  5688. -of_at91_clk_plldiv_setup(struct device_node *np, struct at91_pmc *pmc)
  5689. +of_at91sam9x5_clk_plldiv_setup(struct device_node *np)
  5690. {
  5691. struct clk *clk;
  5692. const char *parent_name;
  5693. const char *name = np->name;
  5694. + struct regmap *regmap;
  5695. parent_name = of_clk_get_parent_name(np, 0);
  5696. of_property_read_string(np, "clock-output-names", &name);
  5697. - clk = at91_clk_register_plldiv(pmc, name, parent_name);
  5698. + regmap = syscon_node_to_regmap(of_get_parent(np));
  5699. + if (IS_ERR(regmap))
  5700. + return;
  5701. + clk = at91_clk_register_plldiv(regmap, name, parent_name);
  5702. if (IS_ERR(clk))
  5703. return;
  5704. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  5705. return;
  5706. }
  5707. -
  5708. -void __init of_at91sam9x5_clk_plldiv_setup(struct device_node *np,
  5709. - struct at91_pmc *pmc)
  5710. -{
  5711. - of_at91_clk_plldiv_setup(np, pmc);
  5712. -}
  5713. +CLK_OF_DECLARE(at91sam9x5_clk_plldiv, "atmel,at91sam9x5-clk-plldiv",
  5714. + of_at91sam9x5_clk_plldiv_setup);
  5715. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-programmable.c linux-4.4.13/drivers/clk/at91/clk-programmable.c
  5716. --- linux-4.4.13.orig/drivers/clk/at91/clk-programmable.c 2016-06-08 03:14:51.000000000 +0200
  5717. +++ linux-4.4.13/drivers/clk/at91/clk-programmable.c 2016-06-22 21:55:07.998523867 +0200
  5718. @@ -12,10 +12,8 @@
  5719. #include <linux/clkdev.h>
  5720. #include <linux/clk/at91_pmc.h>
  5721. #include <linux/of.h>
  5722. -#include <linux/of_address.h>
  5723. -#include <linux/io.h>
  5724. -#include <linux/wait.h>
  5725. -#include <linux/sched.h>
  5726. +#include <linux/mfd/syscon.h>
  5727. +#include <linux/regmap.h>
  5728. #include "pmc.h"
  5729. @@ -24,6 +22,7 @@
  5730. #define PROG_STATUS_MASK(id) (1 << ((id) + 8))
  5731. #define PROG_PRES_MASK 0x7
  5732. +#define PROG_PRES(layout, pckr) ((pckr >> layout->pres_shift) & PROG_PRES_MASK)
  5733. #define PROG_MAX_RM9200_CSS 3
  5734. struct clk_programmable_layout {
  5735. @@ -34,7 +33,7 @@
  5736. struct clk_programmable {
  5737. struct clk_hw hw;
  5738. - struct at91_pmc *pmc;
  5739. + struct regmap *regmap;
  5740. u8 id;
  5741. const struct clk_programmable_layout *layout;
  5742. };
  5743. @@ -44,14 +43,12 @@
  5744. static unsigned long clk_programmable_recalc_rate(struct clk_hw *hw,
  5745. unsigned long parent_rate)
  5746. {
  5747. - u32 pres;
  5748. struct clk_programmable *prog = to_clk_programmable(hw);
  5749. - struct at91_pmc *pmc = prog->pmc;
  5750. - const struct clk_programmable_layout *layout = prog->layout;
  5751. + unsigned int pckr;
  5752. +
  5753. + regmap_read(prog->regmap, AT91_PMC_PCKR(prog->id), &pckr);
  5754. - pres = (pmc_read(pmc, AT91_PMC_PCKR(prog->id)) >> layout->pres_shift) &
  5755. - PROG_PRES_MASK;
  5756. - return parent_rate >> pres;
  5757. + return parent_rate >> PROG_PRES(prog->layout, pckr);
  5758. }
  5759. static int clk_programmable_determine_rate(struct clk_hw *hw,
  5760. @@ -101,36 +98,36 @@
  5761. {
  5762. struct clk_programmable *prog = to_clk_programmable(hw);
  5763. const struct clk_programmable_layout *layout = prog->layout;
  5764. - struct at91_pmc *pmc = prog->pmc;
  5765. - u32 tmp = pmc_read(pmc, AT91_PMC_PCKR(prog->id)) & ~layout->css_mask;
  5766. + unsigned int mask = layout->css_mask;
  5767. + unsigned int pckr = 0;
  5768. if (layout->have_slck_mck)
  5769. - tmp &= AT91_PMC_CSSMCK_MCK;
  5770. + mask |= AT91_PMC_CSSMCK_MCK;
  5771. if (index > layout->css_mask) {
  5772. - if (index > PROG_MAX_RM9200_CSS && layout->have_slck_mck) {
  5773. - tmp |= AT91_PMC_CSSMCK_MCK;
  5774. - return 0;
  5775. - } else {
  5776. + if (index > PROG_MAX_RM9200_CSS && !layout->have_slck_mck)
  5777. return -EINVAL;
  5778. - }
  5779. +
  5780. + pckr |= AT91_PMC_CSSMCK_MCK;
  5781. }
  5782. - pmc_write(pmc, AT91_PMC_PCKR(prog->id), tmp | index);
  5783. + regmap_update_bits(prog->regmap, AT91_PMC_PCKR(prog->id), mask, pckr);
  5784. +
  5785. return 0;
  5786. }
  5787. static u8 clk_programmable_get_parent(struct clk_hw *hw)
  5788. {
  5789. - u32 tmp;
  5790. - u8 ret;
  5791. struct clk_programmable *prog = to_clk_programmable(hw);
  5792. - struct at91_pmc *pmc = prog->pmc;
  5793. const struct clk_programmable_layout *layout = prog->layout;
  5794. + unsigned int pckr;
  5795. + u8 ret;
  5796. +
  5797. + regmap_read(prog->regmap, AT91_PMC_PCKR(prog->id), &pckr);
  5798. +
  5799. + ret = pckr & layout->css_mask;
  5800. - tmp = pmc_read(pmc, AT91_PMC_PCKR(prog->id));
  5801. - ret = tmp & layout->css_mask;
  5802. - if (layout->have_slck_mck && (tmp & AT91_PMC_CSSMCK_MCK) && !ret)
  5803. + if (layout->have_slck_mck && (pckr & AT91_PMC_CSSMCK_MCK) && !ret)
  5804. ret = PROG_MAX_RM9200_CSS + 1;
  5805. return ret;
  5806. @@ -140,26 +137,27 @@
  5807. unsigned long parent_rate)
  5808. {
  5809. struct clk_programmable *prog = to_clk_programmable(hw);
  5810. - struct at91_pmc *pmc = prog->pmc;
  5811. const struct clk_programmable_layout *layout = prog->layout;
  5812. unsigned long div = parent_rate / rate;
  5813. + unsigned int pckr;
  5814. int shift = 0;
  5815. - u32 tmp = pmc_read(pmc, AT91_PMC_PCKR(prog->id)) &
  5816. - ~(PROG_PRES_MASK << layout->pres_shift);
  5817. +
  5818. + regmap_read(prog->regmap, AT91_PMC_PCKR(prog->id), &pckr);
  5819. if (!div)
  5820. return -EINVAL;
  5821. shift = fls(div) - 1;
  5822. - if (div != (1<<shift))
  5823. + if (div != (1 << shift))
  5824. return -EINVAL;
  5825. if (shift >= PROG_PRES_MASK)
  5826. return -EINVAL;
  5827. - pmc_write(pmc, AT91_PMC_PCKR(prog->id),
  5828. - tmp | (shift << layout->pres_shift));
  5829. + regmap_update_bits(prog->regmap, AT91_PMC_PCKR(prog->id),
  5830. + PROG_PRES_MASK << layout->pres_shift,
  5831. + shift << layout->pres_shift);
  5832. return 0;
  5833. }
  5834. @@ -173,7 +171,7 @@
  5835. };
  5836. static struct clk * __init
  5837. -at91_clk_register_programmable(struct at91_pmc *pmc,
  5838. +at91_clk_register_programmable(struct regmap *regmap,
  5839. const char *name, const char **parent_names,
  5840. u8 num_parents, u8 id,
  5841. const struct clk_programmable_layout *layout)
  5842. @@ -198,7 +196,7 @@
  5843. prog->id = id;
  5844. prog->layout = layout;
  5845. prog->hw.init = &init;
  5846. - prog->pmc = pmc;
  5847. + prog->regmap = regmap;
  5848. clk = clk_register(NULL, &prog->hw);
  5849. if (IS_ERR(clk))
  5850. @@ -226,7 +224,7 @@
  5851. };
  5852. static void __init
  5853. -of_at91_clk_prog_setup(struct device_node *np, struct at91_pmc *pmc,
  5854. +of_at91_clk_prog_setup(struct device_node *np,
  5855. const struct clk_programmable_layout *layout)
  5856. {
  5857. int num;
  5858. @@ -236,6 +234,7 @@
  5859. const char *parent_names[PROG_SOURCE_MAX];
  5860. const char *name;
  5861. struct device_node *progclknp;
  5862. + struct regmap *regmap;
  5863. num_parents = of_clk_get_parent_count(np);
  5864. if (num_parents <= 0 || num_parents > PROG_SOURCE_MAX)
  5865. @@ -247,6 +246,10 @@
  5866. if (!num || num > (PROG_ID_MAX + 1))
  5867. return;
  5868. + regmap = syscon_node_to_regmap(of_get_parent(np));
  5869. + if (IS_ERR(regmap))
  5870. + return;
  5871. +
  5872. for_each_child_of_node(np, progclknp) {
  5873. if (of_property_read_u32(progclknp, "reg", &id))
  5874. continue;
  5875. @@ -254,7 +257,7 @@
  5876. if (of_property_read_string(np, "clock-output-names", &name))
  5877. name = progclknp->name;
  5878. - clk = at91_clk_register_programmable(pmc, name,
  5879. + clk = at91_clk_register_programmable(regmap, name,
  5880. parent_names, num_parents,
  5881. id, layout);
  5882. if (IS_ERR(clk))
  5883. @@ -265,20 +268,23 @@
  5884. }
  5885. -void __init of_at91rm9200_clk_prog_setup(struct device_node *np,
  5886. - struct at91_pmc *pmc)
  5887. +static void __init of_at91rm9200_clk_prog_setup(struct device_node *np)
  5888. {
  5889. - of_at91_clk_prog_setup(np, pmc, &at91rm9200_programmable_layout);
  5890. + of_at91_clk_prog_setup(np, &at91rm9200_programmable_layout);
  5891. }
  5892. +CLK_OF_DECLARE(at91rm9200_clk_prog, "atmel,at91rm9200-clk-programmable",
  5893. + of_at91rm9200_clk_prog_setup);
  5894. -void __init of_at91sam9g45_clk_prog_setup(struct device_node *np,
  5895. - struct at91_pmc *pmc)
  5896. +static void __init of_at91sam9g45_clk_prog_setup(struct device_node *np)
  5897. {
  5898. - of_at91_clk_prog_setup(np, pmc, &at91sam9g45_programmable_layout);
  5899. + of_at91_clk_prog_setup(np, &at91sam9g45_programmable_layout);
  5900. }
  5901. +CLK_OF_DECLARE(at91sam9g45_clk_prog, "atmel,at91sam9g45-clk-programmable",
  5902. + of_at91sam9g45_clk_prog_setup);
  5903. -void __init of_at91sam9x5_clk_prog_setup(struct device_node *np,
  5904. - struct at91_pmc *pmc)
  5905. +static void __init of_at91sam9x5_clk_prog_setup(struct device_node *np)
  5906. {
  5907. - of_at91_clk_prog_setup(np, pmc, &at91sam9x5_programmable_layout);
  5908. + of_at91_clk_prog_setup(np, &at91sam9x5_programmable_layout);
  5909. }
  5910. +CLK_OF_DECLARE(at91sam9x5_clk_prog, "atmel,at91sam9x5-clk-programmable",
  5911. + of_at91sam9x5_clk_prog_setup);
  5912. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-slow.c linux-4.4.13/drivers/clk/at91/clk-slow.c
  5913. --- linux-4.4.13.orig/drivers/clk/at91/clk-slow.c 2016-06-08 03:14:51.000000000 +0200
  5914. +++ linux-4.4.13/drivers/clk/at91/clk-slow.c 2016-06-22 21:55:07.998523867 +0200
  5915. @@ -13,17 +13,11 @@
  5916. #include <linux/clk.h>
  5917. #include <linux/clk-provider.h>
  5918. #include <linux/clkdev.h>
  5919. -#include <linux/slab.h>
  5920. #include <linux/clk/at91_pmc.h>
  5921. #include <linux/delay.h>
  5922. #include <linux/of.h>
  5923. -#include <linux/of_address.h>
  5924. -#include <linux/of_irq.h>
  5925. -#include <linux/io.h>
  5926. -#include <linux/interrupt.h>
  5927. -#include <linux/irq.h>
  5928. -#include <linux/sched.h>
  5929. -#include <linux/wait.h>
  5930. +#include <linux/mfd/syscon.h>
  5931. +#include <linux/regmap.h>
  5932. #include "pmc.h"
  5933. #include "sckc.h"
  5934. @@ -59,7 +53,7 @@
  5935. struct clk_sam9260_slow {
  5936. struct clk_hw hw;
  5937. - struct at91_pmc *pmc;
  5938. + struct regmap *regmap;
  5939. };
  5940. #define to_clk_sam9260_slow(hw) container_of(hw, struct clk_sam9260_slow, hw)
  5941. @@ -393,8 +387,11 @@
  5942. static u8 clk_sam9260_slow_get_parent(struct clk_hw *hw)
  5943. {
  5944. struct clk_sam9260_slow *slowck = to_clk_sam9260_slow(hw);
  5945. + unsigned int status;
  5946. - return !!(pmc_read(slowck->pmc, AT91_PMC_SR) & AT91_PMC_OSCSEL);
  5947. + regmap_read(slowck->regmap, AT91_PMC_SR, &status);
  5948. +
  5949. + return status & AT91_PMC_OSCSEL ? 1 : 0;
  5950. }
  5951. static const struct clk_ops sam9260_slow_ops = {
  5952. @@ -402,7 +399,7 @@
  5953. };
  5954. static struct clk * __init
  5955. -at91_clk_register_sam9260_slow(struct at91_pmc *pmc,
  5956. +at91_clk_register_sam9260_slow(struct regmap *regmap,
  5957. const char *name,
  5958. const char **parent_names,
  5959. int num_parents)
  5960. @@ -411,7 +408,7 @@
  5961. struct clk *clk = NULL;
  5962. struct clk_init_data init;
  5963. - if (!pmc || !name)
  5964. + if (!name)
  5965. return ERR_PTR(-EINVAL);
  5966. if (!parent_names || !num_parents)
  5967. @@ -428,7 +425,7 @@
  5968. init.flags = 0;
  5969. slowck->hw.init = &init;
  5970. - slowck->pmc = pmc;
  5971. + slowck->regmap = regmap;
  5972. clk = clk_register(NULL, &slowck->hw);
  5973. if (IS_ERR(clk))
  5974. @@ -439,29 +436,34 @@
  5975. return clk;
  5976. }
  5977. -void __init of_at91sam9260_clk_slow_setup(struct device_node *np,
  5978. - struct at91_pmc *pmc)
  5979. +static void __init of_at91sam9260_clk_slow_setup(struct device_node *np)
  5980. {
  5981. struct clk *clk;
  5982. const char *parent_names[2];
  5983. int num_parents;
  5984. const char *name = np->name;
  5985. + struct regmap *regmap;
  5986. num_parents = of_clk_get_parent_count(np);
  5987. if (num_parents != 2)
  5988. return;
  5989. of_clk_parent_fill(np, parent_names, num_parents);
  5990. + regmap = syscon_node_to_regmap(of_get_parent(np));
  5991. + if (IS_ERR(regmap))
  5992. + return;
  5993. of_property_read_string(np, "clock-output-names", &name);
  5994. - clk = at91_clk_register_sam9260_slow(pmc, name, parent_names,
  5995. + clk = at91_clk_register_sam9260_slow(regmap, name, parent_names,
  5996. num_parents);
  5997. if (IS_ERR(clk))
  5998. return;
  5999. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  6000. }
  6001. +CLK_OF_DECLARE(at91sam9260_clk_slow, "atmel,at91sam9260-clk-slow",
  6002. + of_at91sam9260_clk_slow_setup);
  6003. /*
  6004. * FIXME: All slow clk users are not properly claiming it (get + prepare +
  6005. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-smd.c linux-4.4.13/drivers/clk/at91/clk-smd.c
  6006. --- linux-4.4.13.orig/drivers/clk/at91/clk-smd.c 2016-06-08 03:14:51.000000000 +0200
  6007. +++ linux-4.4.13/drivers/clk/at91/clk-smd.c 2016-06-22 21:55:07.998523867 +0200
  6008. @@ -12,8 +12,8 @@
  6009. #include <linux/clkdev.h>
  6010. #include <linux/clk/at91_pmc.h>
  6011. #include <linux/of.h>
  6012. -#include <linux/of_address.h>
  6013. -#include <linux/io.h>
  6014. +#include <linux/mfd/syscon.h>
  6015. +#include <linux/regmap.h>
  6016. #include "pmc.h"
  6017. @@ -24,7 +24,7 @@
  6018. struct at91sam9x5_clk_smd {
  6019. struct clk_hw hw;
  6020. - struct at91_pmc *pmc;
  6021. + struct regmap *regmap;
  6022. };
  6023. #define to_at91sam9x5_clk_smd(hw) \
  6024. @@ -33,13 +33,13 @@
  6025. static unsigned long at91sam9x5_clk_smd_recalc_rate(struct clk_hw *hw,
  6026. unsigned long parent_rate)
  6027. {
  6028. - u32 tmp;
  6029. - u8 smddiv;
  6030. struct at91sam9x5_clk_smd *smd = to_at91sam9x5_clk_smd(hw);
  6031. - struct at91_pmc *pmc = smd->pmc;
  6032. + unsigned int smdr;
  6033. + u8 smddiv;
  6034. +
  6035. + regmap_read(smd->regmap, AT91_PMC_SMD, &smdr);
  6036. + smddiv = (smdr & AT91_PMC_SMD_DIV) >> SMD_DIV_SHIFT;
  6037. - tmp = pmc_read(pmc, AT91_PMC_SMD);
  6038. - smddiv = (tmp & AT91_PMC_SMD_DIV) >> SMD_DIV_SHIFT;
  6039. return parent_rate / (smddiv + 1);
  6040. }
  6041. @@ -67,40 +67,38 @@
  6042. static int at91sam9x5_clk_smd_set_parent(struct clk_hw *hw, u8 index)
  6043. {
  6044. - u32 tmp;
  6045. struct at91sam9x5_clk_smd *smd = to_at91sam9x5_clk_smd(hw);
  6046. - struct at91_pmc *pmc = smd->pmc;
  6047. if (index > 1)
  6048. return -EINVAL;
  6049. - tmp = pmc_read(pmc, AT91_PMC_SMD) & ~AT91_PMC_SMDS;
  6050. - if (index)
  6051. - tmp |= AT91_PMC_SMDS;
  6052. - pmc_write(pmc, AT91_PMC_SMD, tmp);
  6053. +
  6054. + regmap_update_bits(smd->regmap, AT91_PMC_SMD, AT91_PMC_SMDS,
  6055. + index ? AT91_PMC_SMDS : 0);
  6056. +
  6057. return 0;
  6058. }
  6059. static u8 at91sam9x5_clk_smd_get_parent(struct clk_hw *hw)
  6060. {
  6061. struct at91sam9x5_clk_smd *smd = to_at91sam9x5_clk_smd(hw);
  6062. - struct at91_pmc *pmc = smd->pmc;
  6063. + unsigned int smdr;
  6064. - return pmc_read(pmc, AT91_PMC_SMD) & AT91_PMC_SMDS;
  6065. + regmap_read(smd->regmap, AT91_PMC_SMD, &smdr);
  6066. +
  6067. + return smdr & AT91_PMC_SMDS;
  6068. }
  6069. static int at91sam9x5_clk_smd_set_rate(struct clk_hw *hw, unsigned long rate,
  6070. unsigned long parent_rate)
  6071. {
  6072. - u32 tmp;
  6073. struct at91sam9x5_clk_smd *smd = to_at91sam9x5_clk_smd(hw);
  6074. - struct at91_pmc *pmc = smd->pmc;
  6075. unsigned long div = parent_rate / rate;
  6076. if (parent_rate % rate || div < 1 || div > (SMD_MAX_DIV + 1))
  6077. return -EINVAL;
  6078. - tmp = pmc_read(pmc, AT91_PMC_SMD) & ~AT91_PMC_SMD_DIV;
  6079. - tmp |= (div - 1) << SMD_DIV_SHIFT;
  6080. - pmc_write(pmc, AT91_PMC_SMD, tmp);
  6081. +
  6082. + regmap_update_bits(smd->regmap, AT91_PMC_SMD, AT91_PMC_SMD_DIV,
  6083. + (div - 1) << SMD_DIV_SHIFT);
  6084. return 0;
  6085. }
  6086. @@ -114,7 +112,7 @@
  6087. };
  6088. static struct clk * __init
  6089. -at91sam9x5_clk_register_smd(struct at91_pmc *pmc, const char *name,
  6090. +at91sam9x5_clk_register_smd(struct regmap *regmap, const char *name,
  6091. const char **parent_names, u8 num_parents)
  6092. {
  6093. struct at91sam9x5_clk_smd *smd;
  6094. @@ -132,7 +130,7 @@
  6095. init.flags = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE;
  6096. smd->hw.init = &init;
  6097. - smd->pmc = pmc;
  6098. + smd->regmap = regmap;
  6099. clk = clk_register(NULL, &smd->hw);
  6100. if (IS_ERR(clk))
  6101. @@ -141,13 +139,13 @@
  6102. return clk;
  6103. }
  6104. -void __init of_at91sam9x5_clk_smd_setup(struct device_node *np,
  6105. - struct at91_pmc *pmc)
  6106. +static void __init of_at91sam9x5_clk_smd_setup(struct device_node *np)
  6107. {
  6108. struct clk *clk;
  6109. int num_parents;
  6110. const char *parent_names[SMD_SOURCE_MAX];
  6111. const char *name = np->name;
  6112. + struct regmap *regmap;
  6113. num_parents = of_clk_get_parent_count(np);
  6114. if (num_parents <= 0 || num_parents > SMD_SOURCE_MAX)
  6115. @@ -157,10 +155,16 @@
  6116. of_property_read_string(np, "clock-output-names", &name);
  6117. - clk = at91sam9x5_clk_register_smd(pmc, name, parent_names,
  6118. + regmap = syscon_node_to_regmap(of_get_parent(np));
  6119. + if (IS_ERR(regmap))
  6120. + return;
  6121. +
  6122. + clk = at91sam9x5_clk_register_smd(regmap, name, parent_names,
  6123. num_parents);
  6124. if (IS_ERR(clk))
  6125. return;
  6126. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  6127. }
  6128. +CLK_OF_DECLARE(at91sam9x5_clk_smd, "atmel,at91sam9x5-clk-smd",
  6129. + of_at91sam9x5_clk_smd_setup);
  6130. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-system.c linux-4.4.13/drivers/clk/at91/clk-system.c
  6131. --- linux-4.4.13.orig/drivers/clk/at91/clk-system.c 2016-06-08 03:14:51.000000000 +0200
  6132. +++ linux-4.4.13/drivers/clk/at91/clk-system.c 2016-06-22 21:55:07.998523867 +0200
  6133. @@ -12,13 +12,8 @@
  6134. #include <linux/clkdev.h>
  6135. #include <linux/clk/at91_pmc.h>
  6136. #include <linux/of.h>
  6137. -#include <linux/of_address.h>
  6138. -#include <linux/io.h>
  6139. -#include <linux/irq.h>
  6140. -#include <linux/of_irq.h>
  6141. -#include <linux/interrupt.h>
  6142. -#include <linux/wait.h>
  6143. -#include <linux/sched.h>
  6144. +#include <linux/mfd/syscon.h>
  6145. +#include <linux/regmap.h>
  6146. #include "pmc.h"
  6147. @@ -29,9 +24,7 @@
  6148. #define to_clk_system(hw) container_of(hw, struct clk_system, hw)
  6149. struct clk_system {
  6150. struct clk_hw hw;
  6151. - struct at91_pmc *pmc;
  6152. - unsigned int irq;
  6153. - wait_queue_head_t wait;
  6154. + struct regmap *regmap;
  6155. u8 id;
  6156. };
  6157. @@ -39,58 +32,54 @@
  6158. {
  6159. return (id >= 8) && (id <= 15);
  6160. }
  6161. -static irqreturn_t clk_system_irq_handler(int irq, void *dev_id)
  6162. +
  6163. +static inline bool clk_system_ready(struct regmap *regmap, int id)
  6164. {
  6165. - struct clk_system *sys = (struct clk_system *)dev_id;
  6166. + unsigned int status;
  6167. - wake_up(&sys->wait);
  6168. - disable_irq_nosync(sys->irq);
  6169. + regmap_read(regmap, AT91_PMC_SR, &status);
  6170. - return IRQ_HANDLED;
  6171. + return status & (1 << id) ? 1 : 0;
  6172. }
  6173. static int clk_system_prepare(struct clk_hw *hw)
  6174. {
  6175. struct clk_system *sys = to_clk_system(hw);
  6176. - struct at91_pmc *pmc = sys->pmc;
  6177. - u32 mask = 1 << sys->id;
  6178. - pmc_write(pmc, AT91_PMC_SCER, mask);
  6179. + regmap_write(sys->regmap, AT91_PMC_SCER, 1 << sys->id);
  6180. if (!is_pck(sys->id))
  6181. return 0;
  6182. - while (!(pmc_read(pmc, AT91_PMC_SR) & mask)) {
  6183. - if (sys->irq) {
  6184. - enable_irq(sys->irq);
  6185. - wait_event(sys->wait,
  6186. - pmc_read(pmc, AT91_PMC_SR) & mask);
  6187. - } else
  6188. - cpu_relax();
  6189. - }
  6190. + while (!clk_system_ready(sys->regmap, sys->id))
  6191. + cpu_relax();
  6192. +
  6193. return 0;
  6194. }
  6195. static void clk_system_unprepare(struct clk_hw *hw)
  6196. {
  6197. struct clk_system *sys = to_clk_system(hw);
  6198. - struct at91_pmc *pmc = sys->pmc;
  6199. - pmc_write(pmc, AT91_PMC_SCDR, 1 << sys->id);
  6200. + regmap_write(sys->regmap, AT91_PMC_SCDR, 1 << sys->id);
  6201. }
  6202. static int clk_system_is_prepared(struct clk_hw *hw)
  6203. {
  6204. struct clk_system *sys = to_clk_system(hw);
  6205. - struct at91_pmc *pmc = sys->pmc;
  6206. + unsigned int status;
  6207. +
  6208. + regmap_read(sys->regmap, AT91_PMC_SCSR, &status);
  6209. - if (!(pmc_read(pmc, AT91_PMC_SCSR) & (1 << sys->id)))
  6210. + if (!(status & (1 << sys->id)))
  6211. return 0;
  6212. if (!is_pck(sys->id))
  6213. return 1;
  6214. - return !!(pmc_read(pmc, AT91_PMC_SR) & (1 << sys->id));
  6215. + regmap_read(sys->regmap, AT91_PMC_SR, &status);
  6216. +
  6217. + return status & (1 << sys->id) ? 1 : 0;
  6218. }
  6219. static const struct clk_ops system_ops = {
  6220. @@ -100,13 +89,12 @@
  6221. };
  6222. static struct clk * __init
  6223. -at91_clk_register_system(struct at91_pmc *pmc, const char *name,
  6224. - const char *parent_name, u8 id, int irq)
  6225. +at91_clk_register_system(struct regmap *regmap, const char *name,
  6226. + const char *parent_name, u8 id)
  6227. {
  6228. struct clk_system *sys;
  6229. struct clk *clk = NULL;
  6230. struct clk_init_data init;
  6231. - int ret;
  6232. if (!parent_name || id > SYSTEM_MAX_ID)
  6233. return ERR_PTR(-EINVAL);
  6234. @@ -123,44 +111,33 @@
  6235. sys->id = id;
  6236. sys->hw.init = &init;
  6237. - sys->pmc = pmc;
  6238. - sys->irq = irq;
  6239. - if (irq) {
  6240. - init_waitqueue_head(&sys->wait);
  6241. - irq_set_status_flags(sys->irq, IRQ_NOAUTOEN);
  6242. - ret = request_irq(sys->irq, clk_system_irq_handler,
  6243. - IRQF_TRIGGER_HIGH, name, sys);
  6244. - if (ret) {
  6245. - kfree(sys);
  6246. - return ERR_PTR(ret);
  6247. - }
  6248. - }
  6249. + sys->regmap = regmap;
  6250. clk = clk_register(NULL, &sys->hw);
  6251. - if (IS_ERR(clk)) {
  6252. - if (irq)
  6253. - free_irq(sys->irq, sys);
  6254. + if (IS_ERR(clk))
  6255. kfree(sys);
  6256. - }
  6257. return clk;
  6258. }
  6259. -static void __init
  6260. -of_at91_clk_sys_setup(struct device_node *np, struct at91_pmc *pmc)
  6261. +static void __init of_at91rm9200_clk_sys_setup(struct device_node *np)
  6262. {
  6263. int num;
  6264. - int irq = 0;
  6265. u32 id;
  6266. struct clk *clk;
  6267. const char *name;
  6268. struct device_node *sysclknp;
  6269. const char *parent_name;
  6270. + struct regmap *regmap;
  6271. num = of_get_child_count(np);
  6272. if (num > (SYSTEM_MAX_ID + 1))
  6273. return;
  6274. + regmap = syscon_node_to_regmap(of_get_parent(np));
  6275. + if (IS_ERR(regmap))
  6276. + return;
  6277. +
  6278. for_each_child_of_node(np, sysclknp) {
  6279. if (of_property_read_u32(sysclknp, "reg", &id))
  6280. continue;
  6281. @@ -168,21 +145,14 @@
  6282. if (of_property_read_string(np, "clock-output-names", &name))
  6283. name = sysclknp->name;
  6284. - if (is_pck(id))
  6285. - irq = irq_of_parse_and_map(sysclknp, 0);
  6286. -
  6287. parent_name = of_clk_get_parent_name(sysclknp, 0);
  6288. - clk = at91_clk_register_system(pmc, name, parent_name, id, irq);
  6289. + clk = at91_clk_register_system(regmap, name, parent_name, id);
  6290. if (IS_ERR(clk))
  6291. continue;
  6292. of_clk_add_provider(sysclknp, of_clk_src_simple_get, clk);
  6293. }
  6294. }
  6295. -
  6296. -void __init of_at91rm9200_clk_sys_setup(struct device_node *np,
  6297. - struct at91_pmc *pmc)
  6298. -{
  6299. - of_at91_clk_sys_setup(np, pmc);
  6300. -}
  6301. +CLK_OF_DECLARE(at91rm9200_clk_sys, "atmel,at91rm9200-clk-system",
  6302. + of_at91rm9200_clk_sys_setup);
  6303. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-usb.c linux-4.4.13/drivers/clk/at91/clk-usb.c
  6304. --- linux-4.4.13.orig/drivers/clk/at91/clk-usb.c 2016-06-08 03:14:51.000000000 +0200
  6305. +++ linux-4.4.13/drivers/clk/at91/clk-usb.c 2016-06-22 21:55:07.998523867 +0200
  6306. @@ -12,8 +12,8 @@
  6307. #include <linux/clkdev.h>
  6308. #include <linux/clk/at91_pmc.h>
  6309. #include <linux/of.h>
  6310. -#include <linux/of_address.h>
  6311. -#include <linux/io.h>
  6312. +#include <linux/mfd/syscon.h>
  6313. +#include <linux/regmap.h>
  6314. #include "pmc.h"
  6315. @@ -27,7 +27,7 @@
  6316. struct at91sam9x5_clk_usb {
  6317. struct clk_hw hw;
  6318. - struct at91_pmc *pmc;
  6319. + struct regmap *regmap;
  6320. };
  6321. #define to_at91sam9x5_clk_usb(hw) \
  6322. @@ -35,7 +35,7 @@
  6323. struct at91rm9200_clk_usb {
  6324. struct clk_hw hw;
  6325. - struct at91_pmc *pmc;
  6326. + struct regmap *regmap;
  6327. u32 divisors[4];
  6328. };
  6329. @@ -45,13 +45,12 @@
  6330. static unsigned long at91sam9x5_clk_usb_recalc_rate(struct clk_hw *hw,
  6331. unsigned long parent_rate)
  6332. {
  6333. - u32 tmp;
  6334. - u8 usbdiv;
  6335. struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
  6336. - struct at91_pmc *pmc = usb->pmc;
  6337. + unsigned int usbr;
  6338. + u8 usbdiv;
  6339. - tmp = pmc_read(pmc, AT91_PMC_USB);
  6340. - usbdiv = (tmp & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT;
  6341. + regmap_read(usb->regmap, AT91_PMC_USB, &usbr);
  6342. + usbdiv = (usbr & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT;
  6343. return DIV_ROUND_CLOSEST(parent_rate, (usbdiv + 1));
  6344. }
  6345. @@ -109,33 +108,31 @@
  6346. static int at91sam9x5_clk_usb_set_parent(struct clk_hw *hw, u8 index)
  6347. {
  6348. - u32 tmp;
  6349. struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
  6350. - struct at91_pmc *pmc = usb->pmc;
  6351. if (index > 1)
  6352. return -EINVAL;
  6353. - tmp = pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_USBS;
  6354. - if (index)
  6355. - tmp |= AT91_PMC_USBS;
  6356. - pmc_write(pmc, AT91_PMC_USB, tmp);
  6357. +
  6358. + regmap_update_bits(usb->regmap, AT91_PMC_USB, AT91_PMC_USBS,
  6359. + index ? AT91_PMC_USBS : 0);
  6360. +
  6361. return 0;
  6362. }
  6363. static u8 at91sam9x5_clk_usb_get_parent(struct clk_hw *hw)
  6364. {
  6365. struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
  6366. - struct at91_pmc *pmc = usb->pmc;
  6367. + unsigned int usbr;
  6368. - return pmc_read(pmc, AT91_PMC_USB) & AT91_PMC_USBS;
  6369. + regmap_read(usb->regmap, AT91_PMC_USB, &usbr);
  6370. +
  6371. + return usbr & AT91_PMC_USBS;
  6372. }
  6373. static int at91sam9x5_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate,
  6374. unsigned long parent_rate)
  6375. {
  6376. - u32 tmp;
  6377. struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
  6378. - struct at91_pmc *pmc = usb->pmc;
  6379. unsigned long div;
  6380. if (!rate)
  6381. @@ -145,9 +142,8 @@
  6382. if (div > SAM9X5_USB_MAX_DIV + 1 || !div)
  6383. return -EINVAL;
  6384. - tmp = pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_OHCIUSBDIV;
  6385. - tmp |= (div - 1) << SAM9X5_USB_DIV_SHIFT;
  6386. - pmc_write(pmc, AT91_PMC_USB, tmp);
  6387. + regmap_update_bits(usb->regmap, AT91_PMC_USB, AT91_PMC_OHCIUSBDIV,
  6388. + (div - 1) << SAM9X5_USB_DIV_SHIFT);
  6389. return 0;
  6390. }
  6391. @@ -163,28 +159,28 @@
  6392. static int at91sam9n12_clk_usb_enable(struct clk_hw *hw)
  6393. {
  6394. struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
  6395. - struct at91_pmc *pmc = usb->pmc;
  6396. - pmc_write(pmc, AT91_PMC_USB,
  6397. - pmc_read(pmc, AT91_PMC_USB) | AT91_PMC_USBS);
  6398. + regmap_update_bits(usb->regmap, AT91_PMC_USB, AT91_PMC_USBS,
  6399. + AT91_PMC_USBS);
  6400. +
  6401. return 0;
  6402. }
  6403. static void at91sam9n12_clk_usb_disable(struct clk_hw *hw)
  6404. {
  6405. struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
  6406. - struct at91_pmc *pmc = usb->pmc;
  6407. - pmc_write(pmc, AT91_PMC_USB,
  6408. - pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_USBS);
  6409. + regmap_update_bits(usb->regmap, AT91_PMC_USB, AT91_PMC_USBS, 0);
  6410. }
  6411. static int at91sam9n12_clk_usb_is_enabled(struct clk_hw *hw)
  6412. {
  6413. struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
  6414. - struct at91_pmc *pmc = usb->pmc;
  6415. + unsigned int usbr;
  6416. - return !!(pmc_read(pmc, AT91_PMC_USB) & AT91_PMC_USBS);
  6417. + regmap_read(usb->regmap, AT91_PMC_USB, &usbr);
  6418. +
  6419. + return usbr & AT91_PMC_USBS;
  6420. }
  6421. static const struct clk_ops at91sam9n12_usb_ops = {
  6422. @@ -197,7 +193,7 @@
  6423. };
  6424. static struct clk * __init
  6425. -at91sam9x5_clk_register_usb(struct at91_pmc *pmc, const char *name,
  6426. +at91sam9x5_clk_register_usb(struct regmap *regmap, const char *name,
  6427. const char **parent_names, u8 num_parents)
  6428. {
  6429. struct at91sam9x5_clk_usb *usb;
  6430. @@ -216,7 +212,7 @@
  6431. CLK_SET_RATE_PARENT;
  6432. usb->hw.init = &init;
  6433. - usb->pmc = pmc;
  6434. + usb->regmap = regmap;
  6435. clk = clk_register(NULL, &usb->hw);
  6436. if (IS_ERR(clk))
  6437. @@ -226,7 +222,7 @@
  6438. }
  6439. static struct clk * __init
  6440. -at91sam9n12_clk_register_usb(struct at91_pmc *pmc, const char *name,
  6441. +at91sam9n12_clk_register_usb(struct regmap *regmap, const char *name,
  6442. const char *parent_name)
  6443. {
  6444. struct at91sam9x5_clk_usb *usb;
  6445. @@ -244,7 +240,7 @@
  6446. init.flags = CLK_SET_RATE_GATE | CLK_SET_RATE_PARENT;
  6447. usb->hw.init = &init;
  6448. - usb->pmc = pmc;
  6449. + usb->regmap = regmap;
  6450. clk = clk_register(NULL, &usb->hw);
  6451. if (IS_ERR(clk))
  6452. @@ -257,12 +253,12 @@
  6453. unsigned long parent_rate)
  6454. {
  6455. struct at91rm9200_clk_usb *usb = to_at91rm9200_clk_usb(hw);
  6456. - struct at91_pmc *pmc = usb->pmc;
  6457. - u32 tmp;
  6458. + unsigned int pllbr;
  6459. u8 usbdiv;
  6460. - tmp = pmc_read(pmc, AT91_CKGR_PLLBR);
  6461. - usbdiv = (tmp & AT91_PMC_USBDIV) >> RM9200_USB_DIV_SHIFT;
  6462. + regmap_read(usb->regmap, AT91_CKGR_PLLBR, &pllbr);
  6463. +
  6464. + usbdiv = (pllbr & AT91_PMC_USBDIV) >> RM9200_USB_DIV_SHIFT;
  6465. if (usb->divisors[usbdiv])
  6466. return parent_rate / usb->divisors[usbdiv];
  6467. @@ -310,10 +306,8 @@
  6468. static int at91rm9200_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate,
  6469. unsigned long parent_rate)
  6470. {
  6471. - u32 tmp;
  6472. int i;
  6473. struct at91rm9200_clk_usb *usb = to_at91rm9200_clk_usb(hw);
  6474. - struct at91_pmc *pmc = usb->pmc;
  6475. unsigned long div;
  6476. if (!rate)
  6477. @@ -323,10 +317,10 @@
  6478. for (i = 0; i < RM9200_USB_DIV_TAB_SIZE; i++) {
  6479. if (usb->divisors[i] == div) {
  6480. - tmp = pmc_read(pmc, AT91_CKGR_PLLBR) &
  6481. - ~AT91_PMC_USBDIV;
  6482. - tmp |= i << RM9200_USB_DIV_SHIFT;
  6483. - pmc_write(pmc, AT91_CKGR_PLLBR, tmp);
  6484. + regmap_update_bits(usb->regmap, AT91_CKGR_PLLBR,
  6485. + AT91_PMC_USBDIV,
  6486. + i << RM9200_USB_DIV_SHIFT);
  6487. +
  6488. return 0;
  6489. }
  6490. }
  6491. @@ -341,7 +335,7 @@
  6492. };
  6493. static struct clk * __init
  6494. -at91rm9200_clk_register_usb(struct at91_pmc *pmc, const char *name,
  6495. +at91rm9200_clk_register_usb(struct regmap *regmap, const char *name,
  6496. const char *parent_name, const u32 *divisors)
  6497. {
  6498. struct at91rm9200_clk_usb *usb;
  6499. @@ -359,7 +353,7 @@
  6500. init.flags = CLK_SET_RATE_PARENT;
  6501. usb->hw.init = &init;
  6502. - usb->pmc = pmc;
  6503. + usb->regmap = regmap;
  6504. memcpy(usb->divisors, divisors, sizeof(usb->divisors));
  6505. clk = clk_register(NULL, &usb->hw);
  6506. @@ -369,13 +363,13 @@
  6507. return clk;
  6508. }
  6509. -void __init of_at91sam9x5_clk_usb_setup(struct device_node *np,
  6510. - struct at91_pmc *pmc)
  6511. +static void __init of_at91sam9x5_clk_usb_setup(struct device_node *np)
  6512. {
  6513. struct clk *clk;
  6514. int num_parents;
  6515. const char *parent_names[USB_SOURCE_MAX];
  6516. const char *name = np->name;
  6517. + struct regmap *regmap;
  6518. num_parents = of_clk_get_parent_count(np);
  6519. if (num_parents <= 0 || num_parents > USB_SOURCE_MAX)
  6520. @@ -385,19 +379,26 @@
  6521. of_property_read_string(np, "clock-output-names", &name);
  6522. - clk = at91sam9x5_clk_register_usb(pmc, name, parent_names, num_parents);
  6523. + regmap = syscon_node_to_regmap(of_get_parent(np));
  6524. + if (IS_ERR(regmap))
  6525. + return;
  6526. +
  6527. + clk = at91sam9x5_clk_register_usb(regmap, name, parent_names,
  6528. + num_parents);
  6529. if (IS_ERR(clk))
  6530. return;
  6531. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  6532. }
  6533. +CLK_OF_DECLARE(at91sam9x5_clk_usb, "atmel,at91sam9x5-clk-usb",
  6534. + of_at91sam9x5_clk_usb_setup);
  6535. -void __init of_at91sam9n12_clk_usb_setup(struct device_node *np,
  6536. - struct at91_pmc *pmc)
  6537. +static void __init of_at91sam9n12_clk_usb_setup(struct device_node *np)
  6538. {
  6539. struct clk *clk;
  6540. const char *parent_name;
  6541. const char *name = np->name;
  6542. + struct regmap *regmap;
  6543. parent_name = of_clk_get_parent_name(np, 0);
  6544. if (!parent_name)
  6545. @@ -405,20 +406,26 @@
  6546. of_property_read_string(np, "clock-output-names", &name);
  6547. - clk = at91sam9n12_clk_register_usb(pmc, name, parent_name);
  6548. + regmap = syscon_node_to_regmap(of_get_parent(np));
  6549. + if (IS_ERR(regmap))
  6550. + return;
  6551. +
  6552. + clk = at91sam9n12_clk_register_usb(regmap, name, parent_name);
  6553. if (IS_ERR(clk))
  6554. return;
  6555. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  6556. }
  6557. +CLK_OF_DECLARE(at91sam9n12_clk_usb, "atmel,at91sam9n12-clk-usb",
  6558. + of_at91sam9n12_clk_usb_setup);
  6559. -void __init of_at91rm9200_clk_usb_setup(struct device_node *np,
  6560. - struct at91_pmc *pmc)
  6561. +static void __init of_at91rm9200_clk_usb_setup(struct device_node *np)
  6562. {
  6563. struct clk *clk;
  6564. const char *parent_name;
  6565. const char *name = np->name;
  6566. u32 divisors[4] = {0, 0, 0, 0};
  6567. + struct regmap *regmap;
  6568. parent_name = of_clk_get_parent_name(np, 0);
  6569. if (!parent_name)
  6570. @@ -430,9 +437,15 @@
  6571. of_property_read_string(np, "clock-output-names", &name);
  6572. - clk = at91rm9200_clk_register_usb(pmc, name, parent_name, divisors);
  6573. + regmap = syscon_node_to_regmap(of_get_parent(np));
  6574. + if (IS_ERR(regmap))
  6575. + return;
  6576. +
  6577. + clk = at91rm9200_clk_register_usb(regmap, name, parent_name, divisors);
  6578. if (IS_ERR(clk))
  6579. return;
  6580. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  6581. }
  6582. +CLK_OF_DECLARE(at91rm9200_clk_usb, "atmel,at91rm9200-clk-usb",
  6583. + of_at91rm9200_clk_usb_setup);
  6584. diff -Nur linux-4.4.13.orig/drivers/clk/at91/clk-utmi.c linux-4.4.13/drivers/clk/at91/clk-utmi.c
  6585. --- linux-4.4.13.orig/drivers/clk/at91/clk-utmi.c 2016-06-08 03:14:51.000000000 +0200
  6586. +++ linux-4.4.13/drivers/clk/at91/clk-utmi.c 2016-06-22 21:55:07.998523867 +0200
  6587. @@ -11,14 +11,9 @@
  6588. #include <linux/clk-provider.h>
  6589. #include <linux/clkdev.h>
  6590. #include <linux/clk/at91_pmc.h>
  6591. -#include <linux/interrupt.h>
  6592. -#include <linux/irq.h>
  6593. #include <linux/of.h>
  6594. -#include <linux/of_address.h>
  6595. -#include <linux/of_irq.h>
  6596. -#include <linux/io.h>
  6597. -#include <linux/sched.h>
  6598. -#include <linux/wait.h>
  6599. +#include <linux/mfd/syscon.h>
  6600. +#include <linux/regmap.h>
  6601. #include "pmc.h"
  6602. @@ -26,37 +21,30 @@
  6603. struct clk_utmi {
  6604. struct clk_hw hw;
  6605. - struct at91_pmc *pmc;
  6606. - unsigned int irq;
  6607. - wait_queue_head_t wait;
  6608. + struct regmap *regmap;
  6609. };
  6610. #define to_clk_utmi(hw) container_of(hw, struct clk_utmi, hw)
  6611. -static irqreturn_t clk_utmi_irq_handler(int irq, void *dev_id)
  6612. +static inline bool clk_utmi_ready(struct regmap *regmap)
  6613. {
  6614. - struct clk_utmi *utmi = (struct clk_utmi *)dev_id;
  6615. + unsigned int status;
  6616. - wake_up(&utmi->wait);
  6617. - disable_irq_nosync(utmi->irq);
  6618. + regmap_read(regmap, AT91_PMC_SR, &status);
  6619. - return IRQ_HANDLED;
  6620. + return status & AT91_PMC_LOCKU;
  6621. }
  6622. static int clk_utmi_prepare(struct clk_hw *hw)
  6623. {
  6624. struct clk_utmi *utmi = to_clk_utmi(hw);
  6625. - struct at91_pmc *pmc = utmi->pmc;
  6626. - u32 tmp = pmc_read(pmc, AT91_CKGR_UCKR) | AT91_PMC_UPLLEN |
  6627. - AT91_PMC_UPLLCOUNT | AT91_PMC_BIASEN;
  6628. -
  6629. - pmc_write(pmc, AT91_CKGR_UCKR, tmp);
  6630. -
  6631. - while (!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_LOCKU)) {
  6632. - enable_irq(utmi->irq);
  6633. - wait_event(utmi->wait,
  6634. - pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_LOCKU);
  6635. - }
  6636. + unsigned int uckr = AT91_PMC_UPLLEN | AT91_PMC_UPLLCOUNT |
  6637. + AT91_PMC_BIASEN;
  6638. +
  6639. + regmap_update_bits(utmi->regmap, AT91_CKGR_UCKR, uckr, uckr);
  6640. +
  6641. + while (!clk_utmi_ready(utmi->regmap))
  6642. + cpu_relax();
  6643. return 0;
  6644. }
  6645. @@ -64,18 +52,15 @@
  6646. static int clk_utmi_is_prepared(struct clk_hw *hw)
  6647. {
  6648. struct clk_utmi *utmi = to_clk_utmi(hw);
  6649. - struct at91_pmc *pmc = utmi->pmc;
  6650. - return !!(pmc_read(pmc, AT91_PMC_SR) & AT91_PMC_LOCKU);
  6651. + return clk_utmi_ready(utmi->regmap);
  6652. }
  6653. static void clk_utmi_unprepare(struct clk_hw *hw)
  6654. {
  6655. struct clk_utmi *utmi = to_clk_utmi(hw);
  6656. - struct at91_pmc *pmc = utmi->pmc;
  6657. - u32 tmp = pmc_read(pmc, AT91_CKGR_UCKR) & ~AT91_PMC_UPLLEN;
  6658. - pmc_write(pmc, AT91_CKGR_UCKR, tmp);
  6659. + regmap_update_bits(utmi->regmap, AT91_CKGR_UCKR, AT91_PMC_UPLLEN, 0);
  6660. }
  6661. static unsigned long clk_utmi_recalc_rate(struct clk_hw *hw,
  6662. @@ -93,10 +78,9 @@
  6663. };
  6664. static struct clk * __init
  6665. -at91_clk_register_utmi(struct at91_pmc *pmc, unsigned int irq,
  6666. +at91_clk_register_utmi(struct regmap *regmap,
  6667. const char *name, const char *parent_name)
  6668. {
  6669. - int ret;
  6670. struct clk_utmi *utmi;
  6671. struct clk *clk = NULL;
  6672. struct clk_init_data init;
  6673. @@ -112,52 +96,36 @@
  6674. init.flags = CLK_SET_RATE_GATE;
  6675. utmi->hw.init = &init;
  6676. - utmi->pmc = pmc;
  6677. - utmi->irq = irq;
  6678. - init_waitqueue_head(&utmi->wait);
  6679. - irq_set_status_flags(utmi->irq, IRQ_NOAUTOEN);
  6680. - ret = request_irq(utmi->irq, clk_utmi_irq_handler,
  6681. - IRQF_TRIGGER_HIGH, "clk-utmi", utmi);
  6682. - if (ret) {
  6683. - kfree(utmi);
  6684. - return ERR_PTR(ret);
  6685. - }
  6686. + utmi->regmap = regmap;
  6687. clk = clk_register(NULL, &utmi->hw);
  6688. - if (IS_ERR(clk)) {
  6689. - free_irq(utmi->irq, utmi);
  6690. + if (IS_ERR(clk))
  6691. kfree(utmi);
  6692. - }
  6693. return clk;
  6694. }
  6695. -static void __init
  6696. -of_at91_clk_utmi_setup(struct device_node *np, struct at91_pmc *pmc)
  6697. +static void __init of_at91sam9x5_clk_utmi_setup(struct device_node *np)
  6698. {
  6699. - unsigned int irq;
  6700. struct clk *clk;
  6701. const char *parent_name;
  6702. const char *name = np->name;
  6703. + struct regmap *regmap;
  6704. parent_name = of_clk_get_parent_name(np, 0);
  6705. of_property_read_string(np, "clock-output-names", &name);
  6706. - irq = irq_of_parse_and_map(np, 0);
  6707. - if (!irq)
  6708. + regmap = syscon_node_to_regmap(of_get_parent(np));
  6709. + if (IS_ERR(regmap))
  6710. return;
  6711. - clk = at91_clk_register_utmi(pmc, irq, name, parent_name);
  6712. + clk = at91_clk_register_utmi(regmap, name, parent_name);
  6713. if (IS_ERR(clk))
  6714. return;
  6715. of_clk_add_provider(np, of_clk_src_simple_get, clk);
  6716. return;
  6717. }
  6718. -
  6719. -void __init of_at91sam9x5_clk_utmi_setup(struct device_node *np,
  6720. - struct at91_pmc *pmc)
  6721. -{
  6722. - of_at91_clk_utmi_setup(np, pmc);
  6723. -}
  6724. +CLK_OF_DECLARE(at91sam9x5_clk_utmi, "atmel,at91sam9x5-clk-utmi",
  6725. + of_at91sam9x5_clk_utmi_setup);
  6726. diff -Nur linux-4.4.13.orig/drivers/clk/at91/pmc.c linux-4.4.13/drivers/clk/at91/pmc.c
  6727. --- linux-4.4.13.orig/drivers/clk/at91/pmc.c 2016-06-08 03:14:51.000000000 +0200
  6728. +++ linux-4.4.13/drivers/clk/at91/pmc.c 2016-06-22 21:55:07.998523867 +0200
  6729. @@ -12,36 +12,13 @@
  6730. #include <linux/clkdev.h>
  6731. #include <linux/clk/at91_pmc.h>
  6732. #include <linux/of.h>
  6733. -#include <linux/of_address.h>
  6734. -#include <linux/io.h>
  6735. -#include <linux/interrupt.h>
  6736. -#include <linux/irq.h>
  6737. -#include <linux/irqchip/chained_irq.h>
  6738. -#include <linux/irqdomain.h>
  6739. -#include <linux/of_irq.h>
  6740. +#include <linux/mfd/syscon.h>
  6741. +#include <linux/regmap.h>
  6742. #include <asm/proc-fns.h>
  6743. #include "pmc.h"
  6744. -void __iomem *at91_pmc_base;
  6745. -EXPORT_SYMBOL_GPL(at91_pmc_base);
  6746. -
  6747. -void at91rm9200_idle(void)
  6748. -{
  6749. - /*
  6750. - * Disable the processor clock. The processor will be automatically
  6751. - * re-enabled by an interrupt or by a reset.
  6752. - */
  6753. - at91_pmc_write(AT91_PMC_SCDR, AT91_PMC_PCK);
  6754. -}
  6755. -
  6756. -void at91sam9_idle(void)
  6757. -{
  6758. - at91_pmc_write(AT91_PMC_SCDR, AT91_PMC_PCK);
  6759. - cpu_do_idle();
  6760. -}
  6761. -
  6762. int of_at91_get_clk_range(struct device_node *np, const char *propname,
  6763. struct clk_range *range)
  6764. {
  6765. @@ -64,402 +41,3 @@
  6766. return 0;
  6767. }
  6768. EXPORT_SYMBOL_GPL(of_at91_get_clk_range);
  6769. -
  6770. -static void pmc_irq_mask(struct irq_data *d)
  6771. -{
  6772. - struct at91_pmc *pmc = irq_data_get_irq_chip_data(d);
  6773. -
  6774. - pmc_write(pmc, AT91_PMC_IDR, 1 << d->hwirq);
  6775. -}
  6776. -
  6777. -static void pmc_irq_unmask(struct irq_data *d)
  6778. -{
  6779. - struct at91_pmc *pmc = irq_data_get_irq_chip_data(d);
  6780. -
  6781. - pmc_write(pmc, AT91_PMC_IER, 1 << d->hwirq);
  6782. -}
  6783. -
  6784. -static int pmc_irq_set_type(struct irq_data *d, unsigned type)
  6785. -{
  6786. - if (type != IRQ_TYPE_LEVEL_HIGH) {
  6787. - pr_warn("PMC: type not supported (support only IRQ_TYPE_LEVEL_HIGH type)\n");
  6788. - return -EINVAL;
  6789. - }
  6790. -
  6791. - return 0;
  6792. -}
  6793. -
  6794. -static void pmc_irq_suspend(struct irq_data *d)
  6795. -{
  6796. - struct at91_pmc *pmc = irq_data_get_irq_chip_data(d);
  6797. -
  6798. - pmc->imr = pmc_read(pmc, AT91_PMC_IMR);
  6799. - pmc_write(pmc, AT91_PMC_IDR, pmc->imr);
  6800. -}
  6801. -
  6802. -static void pmc_irq_resume(struct irq_data *d)
  6803. -{
  6804. - struct at91_pmc *pmc = irq_data_get_irq_chip_data(d);
  6805. -
  6806. - pmc_write(pmc, AT91_PMC_IER, pmc->imr);
  6807. -}
  6808. -
  6809. -static struct irq_chip pmc_irq = {
  6810. - .name = "PMC",
  6811. - .irq_disable = pmc_irq_mask,
  6812. - .irq_mask = pmc_irq_mask,
  6813. - .irq_unmask = pmc_irq_unmask,
  6814. - .irq_set_type = pmc_irq_set_type,
  6815. - .irq_suspend = pmc_irq_suspend,
  6816. - .irq_resume = pmc_irq_resume,
  6817. -};
  6818. -
  6819. -static struct lock_class_key pmc_lock_class;
  6820. -
  6821. -static int pmc_irq_map(struct irq_domain *h, unsigned int virq,
  6822. - irq_hw_number_t hw)
  6823. -{
  6824. - struct at91_pmc *pmc = h->host_data;
  6825. -
  6826. - irq_set_lockdep_class(virq, &pmc_lock_class);
  6827. -
  6828. - irq_set_chip_and_handler(virq, &pmc_irq,
  6829. - handle_level_irq);
  6830. - irq_set_chip_data(virq, pmc);
  6831. -
  6832. - return 0;
  6833. -}
  6834. -
  6835. -static int pmc_irq_domain_xlate(struct irq_domain *d,
  6836. - struct device_node *ctrlr,
  6837. - const u32 *intspec, unsigned int intsize,
  6838. - irq_hw_number_t *out_hwirq,
  6839. - unsigned int *out_type)
  6840. -{
  6841. - struct at91_pmc *pmc = d->host_data;
  6842. - const struct at91_pmc_caps *caps = pmc->caps;
  6843. -
  6844. - if (WARN_ON(intsize < 1))
  6845. - return -EINVAL;
  6846. -
  6847. - *out_hwirq = intspec[0];
  6848. -
  6849. - if (!(caps->available_irqs & (1 << *out_hwirq)))
  6850. - return -EINVAL;
  6851. -
  6852. - *out_type = IRQ_TYPE_LEVEL_HIGH;
  6853. -
  6854. - return 0;
  6855. -}
  6856. -
  6857. -static const struct irq_domain_ops pmc_irq_ops = {
  6858. - .map = pmc_irq_map,
  6859. - .xlate = pmc_irq_domain_xlate,
  6860. -};
  6861. -
  6862. -static irqreturn_t pmc_irq_handler(int irq, void *data)
  6863. -{
  6864. - struct at91_pmc *pmc = (struct at91_pmc *)data;
  6865. - unsigned long sr;
  6866. - int n;
  6867. -
  6868. - sr = pmc_read(pmc, AT91_PMC_SR) & pmc_read(pmc, AT91_PMC_IMR);
  6869. - if (!sr)
  6870. - return IRQ_NONE;
  6871. -
  6872. - for_each_set_bit(n, &sr, BITS_PER_LONG)
  6873. - generic_handle_irq(irq_find_mapping(pmc->irqdomain, n));
  6874. -
  6875. - return IRQ_HANDLED;
  6876. -}
  6877. -
  6878. -static const struct at91_pmc_caps at91rm9200_caps = {
  6879. - .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_LOCKB |
  6880. - AT91_PMC_MCKRDY | AT91_PMC_PCK0RDY |
  6881. - AT91_PMC_PCK1RDY | AT91_PMC_PCK2RDY |
  6882. - AT91_PMC_PCK3RDY,
  6883. -};
  6884. -
  6885. -static const struct at91_pmc_caps at91sam9260_caps = {
  6886. - .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_LOCKB |
  6887. - AT91_PMC_MCKRDY | AT91_PMC_PCK0RDY |
  6888. - AT91_PMC_PCK1RDY,
  6889. -};
  6890. -
  6891. -static const struct at91_pmc_caps at91sam9g45_caps = {
  6892. - .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_MCKRDY |
  6893. - AT91_PMC_LOCKU | AT91_PMC_PCK0RDY |
  6894. - AT91_PMC_PCK1RDY,
  6895. -};
  6896. -
  6897. -static const struct at91_pmc_caps at91sam9n12_caps = {
  6898. - .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_LOCKB |
  6899. - AT91_PMC_MCKRDY | AT91_PMC_PCK0RDY |
  6900. - AT91_PMC_PCK1RDY | AT91_PMC_MOSCSELS |
  6901. - AT91_PMC_MOSCRCS | AT91_PMC_CFDEV,
  6902. -};
  6903. -
  6904. -static const struct at91_pmc_caps at91sam9x5_caps = {
  6905. - .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_MCKRDY |
  6906. - AT91_PMC_LOCKU | AT91_PMC_PCK0RDY |
  6907. - AT91_PMC_PCK1RDY | AT91_PMC_MOSCSELS |
  6908. - AT91_PMC_MOSCRCS | AT91_PMC_CFDEV,
  6909. -};
  6910. -
  6911. -static const struct at91_pmc_caps sama5d2_caps = {
  6912. - .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_MCKRDY |
  6913. - AT91_PMC_LOCKU | AT91_PMC_PCK0RDY |
  6914. - AT91_PMC_PCK1RDY | AT91_PMC_PCK2RDY |
  6915. - AT91_PMC_MOSCSELS | AT91_PMC_MOSCRCS |
  6916. - AT91_PMC_CFDEV | AT91_PMC_GCKRDY,
  6917. -};
  6918. -
  6919. -static const struct at91_pmc_caps sama5d3_caps = {
  6920. - .available_irqs = AT91_PMC_MOSCS | AT91_PMC_LOCKA | AT91_PMC_MCKRDY |
  6921. - AT91_PMC_LOCKU | AT91_PMC_PCK0RDY |
  6922. - AT91_PMC_PCK1RDY | AT91_PMC_PCK2RDY |
  6923. - AT91_PMC_MOSCSELS | AT91_PMC_MOSCRCS |
  6924. - AT91_PMC_CFDEV,
  6925. -};
  6926. -
  6927. -static struct at91_pmc *__init at91_pmc_init(struct device_node *np,
  6928. - void __iomem *regbase, int virq,
  6929. - const struct at91_pmc_caps *caps)
  6930. -{
  6931. - struct at91_pmc *pmc;
  6932. -
  6933. - if (!regbase || !virq || !caps)
  6934. - return NULL;
  6935. -
  6936. - at91_pmc_base = regbase;
  6937. -
  6938. - pmc = kzalloc(sizeof(*pmc), GFP_KERNEL);
  6939. - if (!pmc)
  6940. - return NULL;
  6941. -
  6942. - spin_lock_init(&pmc->lock);
  6943. - pmc->regbase = regbase;
  6944. - pmc->virq = virq;
  6945. - pmc->caps = caps;
  6946. -
  6947. - pmc->irqdomain = irq_domain_add_linear(np, 32, &pmc_irq_ops, pmc);
  6948. -
  6949. - if (!pmc->irqdomain)
  6950. - goto out_free_pmc;
  6951. -
  6952. - pmc_write(pmc, AT91_PMC_IDR, 0xffffffff);
  6953. - if (request_irq(pmc->virq, pmc_irq_handler,
  6954. - IRQF_SHARED | IRQF_COND_SUSPEND, "pmc", pmc))
  6955. - goto out_remove_irqdomain;
  6956. -
  6957. - return pmc;
  6958. -
  6959. -out_remove_irqdomain:
  6960. - irq_domain_remove(pmc->irqdomain);
  6961. -out_free_pmc:
  6962. - kfree(pmc);
  6963. -
  6964. - return NULL;
  6965. -}
  6966. -
  6967. -static const struct of_device_id pmc_clk_ids[] __initconst = {
  6968. - /* Slow oscillator */
  6969. - {
  6970. - .compatible = "atmel,at91sam9260-clk-slow",
  6971. - .data = of_at91sam9260_clk_slow_setup,
  6972. - },
  6973. - /* Main clock */
  6974. - {
  6975. - .compatible = "atmel,at91rm9200-clk-main-osc",
  6976. - .data = of_at91rm9200_clk_main_osc_setup,
  6977. - },
  6978. - {
  6979. - .compatible = "atmel,at91sam9x5-clk-main-rc-osc",
  6980. - .data = of_at91sam9x5_clk_main_rc_osc_setup,
  6981. - },
  6982. - {
  6983. - .compatible = "atmel,at91rm9200-clk-main",
  6984. - .data = of_at91rm9200_clk_main_setup,
  6985. - },
  6986. - {
  6987. - .compatible = "atmel,at91sam9x5-clk-main",
  6988. - .data = of_at91sam9x5_clk_main_setup,
  6989. - },
  6990. - /* PLL clocks */
  6991. - {
  6992. - .compatible = "atmel,at91rm9200-clk-pll",
  6993. - .data = of_at91rm9200_clk_pll_setup,
  6994. - },
  6995. - {
  6996. - .compatible = "atmel,at91sam9g45-clk-pll",
  6997. - .data = of_at91sam9g45_clk_pll_setup,
  6998. - },
  6999. - {
  7000. - .compatible = "atmel,at91sam9g20-clk-pllb",
  7001. - .data = of_at91sam9g20_clk_pllb_setup,
  7002. - },
  7003. - {
  7004. - .compatible = "atmel,sama5d3-clk-pll",
  7005. - .data = of_sama5d3_clk_pll_setup,
  7006. - },
  7007. - {
  7008. - .compatible = "atmel,at91sam9x5-clk-plldiv",
  7009. - .data = of_at91sam9x5_clk_plldiv_setup,
  7010. - },
  7011. - /* Master clock */
  7012. - {
  7013. - .compatible = "atmel,at91rm9200-clk-master",
  7014. - .data = of_at91rm9200_clk_master_setup,
  7015. - },
  7016. - {
  7017. - .compatible = "atmel,at91sam9x5-clk-master",
  7018. - .data = of_at91sam9x5_clk_master_setup,
  7019. - },
  7020. - /* System clocks */
  7021. - {
  7022. - .compatible = "atmel,at91rm9200-clk-system",
  7023. - .data = of_at91rm9200_clk_sys_setup,
  7024. - },
  7025. - /* Peripheral clocks */
  7026. - {
  7027. - .compatible = "atmel,at91rm9200-clk-peripheral",
  7028. - .data = of_at91rm9200_clk_periph_setup,
  7029. - },
  7030. - {
  7031. - .compatible = "atmel,at91sam9x5-clk-peripheral",
  7032. - .data = of_at91sam9x5_clk_periph_setup,
  7033. - },
  7034. - /* Programmable clocks */
  7035. - {
  7036. - .compatible = "atmel,at91rm9200-clk-programmable",
  7037. - .data = of_at91rm9200_clk_prog_setup,
  7038. - },
  7039. - {
  7040. - .compatible = "atmel,at91sam9g45-clk-programmable",
  7041. - .data = of_at91sam9g45_clk_prog_setup,
  7042. - },
  7043. - {
  7044. - .compatible = "atmel,at91sam9x5-clk-programmable",
  7045. - .data = of_at91sam9x5_clk_prog_setup,
  7046. - },
  7047. - /* UTMI clock */
  7048. -#if defined(CONFIG_HAVE_AT91_UTMI)
  7049. - {
  7050. - .compatible = "atmel,at91sam9x5-clk-utmi",
  7051. - .data = of_at91sam9x5_clk_utmi_setup,
  7052. - },
  7053. -#endif
  7054. - /* USB clock */
  7055. -#if defined(CONFIG_HAVE_AT91_USB_CLK)
  7056. - {
  7057. - .compatible = "atmel,at91rm9200-clk-usb",
  7058. - .data = of_at91rm9200_clk_usb_setup,
  7059. - },
  7060. - {
  7061. - .compatible = "atmel,at91sam9x5-clk-usb",
  7062. - .data = of_at91sam9x5_clk_usb_setup,
  7063. - },
  7064. - {
  7065. - .compatible = "atmel,at91sam9n12-clk-usb",
  7066. - .data = of_at91sam9n12_clk_usb_setup,
  7067. - },
  7068. -#endif
  7069. - /* SMD clock */
  7070. -#if defined(CONFIG_HAVE_AT91_SMD)
  7071. - {
  7072. - .compatible = "atmel,at91sam9x5-clk-smd",
  7073. - .data = of_at91sam9x5_clk_smd_setup,
  7074. - },
  7075. -#endif
  7076. -#if defined(CONFIG_HAVE_AT91_H32MX)
  7077. - {
  7078. - .compatible = "atmel,sama5d4-clk-h32mx",
  7079. - .data = of_sama5d4_clk_h32mx_setup,
  7080. - },
  7081. -#endif
  7082. -#if defined(CONFIG_HAVE_AT91_GENERATED_CLK)
  7083. - {
  7084. - .compatible = "atmel,sama5d2-clk-generated",
  7085. - .data = of_sama5d2_clk_generated_setup,
  7086. - },
  7087. -#endif
  7088. - { /*sentinel*/ }
  7089. -};
  7090. -
  7091. -static void __init of_at91_pmc_setup(struct device_node *np,
  7092. - const struct at91_pmc_caps *caps)
  7093. -{
  7094. - struct at91_pmc *pmc;
  7095. - struct device_node *childnp;
  7096. - void (*clk_setup)(struct device_node *, struct at91_pmc *);
  7097. - const struct of_device_id *clk_id;
  7098. - void __iomem *regbase = of_iomap(np, 0);
  7099. - int virq;
  7100. -
  7101. - if (!regbase)
  7102. - return;
  7103. -
  7104. - virq = irq_of_parse_and_map(np, 0);
  7105. - if (!virq)
  7106. - return;
  7107. -
  7108. - pmc = at91_pmc_init(np, regbase, virq, caps);
  7109. - if (!pmc)
  7110. - return;
  7111. - for_each_child_of_node(np, childnp) {
  7112. - clk_id = of_match_node(pmc_clk_ids, childnp);
  7113. - if (!clk_id)
  7114. - continue;
  7115. - clk_setup = clk_id->data;
  7116. - clk_setup(childnp, pmc);
  7117. - }
  7118. -}
  7119. -
  7120. -static void __init of_at91rm9200_pmc_setup(struct device_node *np)
  7121. -{
  7122. - of_at91_pmc_setup(np, &at91rm9200_caps);
  7123. -}
  7124. -CLK_OF_DECLARE(at91rm9200_clk_pmc, "atmel,at91rm9200-pmc",
  7125. - of_at91rm9200_pmc_setup);
  7126. -
  7127. -static void __init of_at91sam9260_pmc_setup(struct device_node *np)
  7128. -{
  7129. - of_at91_pmc_setup(np, &at91sam9260_caps);
  7130. -}
  7131. -CLK_OF_DECLARE(at91sam9260_clk_pmc, "atmel,at91sam9260-pmc",
  7132. - of_at91sam9260_pmc_setup);
  7133. -
  7134. -static void __init of_at91sam9g45_pmc_setup(struct device_node *np)
  7135. -{
  7136. - of_at91_pmc_setup(np, &at91sam9g45_caps);
  7137. -}
  7138. -CLK_OF_DECLARE(at91sam9g45_clk_pmc, "atmel,at91sam9g45-pmc",
  7139. - of_at91sam9g45_pmc_setup);
  7140. -
  7141. -static void __init of_at91sam9n12_pmc_setup(struct device_node *np)
  7142. -{
  7143. - of_at91_pmc_setup(np, &at91sam9n12_caps);
  7144. -}
  7145. -CLK_OF_DECLARE(at91sam9n12_clk_pmc, "atmel,at91sam9n12-pmc",
  7146. - of_at91sam9n12_pmc_setup);
  7147. -
  7148. -static void __init of_at91sam9x5_pmc_setup(struct device_node *np)
  7149. -{
  7150. - of_at91_pmc_setup(np, &at91sam9x5_caps);
  7151. -}
  7152. -CLK_OF_DECLARE(at91sam9x5_clk_pmc, "atmel,at91sam9x5-pmc",
  7153. - of_at91sam9x5_pmc_setup);
  7154. -
  7155. -static void __init of_sama5d2_pmc_setup(struct device_node *np)
  7156. -{
  7157. - of_at91_pmc_setup(np, &sama5d2_caps);
  7158. -}
  7159. -CLK_OF_DECLARE(sama5d2_clk_pmc, "atmel,sama5d2-pmc",
  7160. - of_sama5d2_pmc_setup);
  7161. -
  7162. -static void __init of_sama5d3_pmc_setup(struct device_node *np)
  7163. -{
  7164. - of_at91_pmc_setup(np, &sama5d3_caps);
  7165. -}
  7166. -CLK_OF_DECLARE(sama5d3_clk_pmc, "atmel,sama5d3-pmc",
  7167. - of_sama5d3_pmc_setup);
  7168. diff -Nur linux-4.4.13.orig/drivers/clk/at91/pmc.h linux-4.4.13/drivers/clk/at91/pmc.h
  7169. --- linux-4.4.13.orig/drivers/clk/at91/pmc.h 2016-06-08 03:14:51.000000000 +0200
  7170. +++ linux-4.4.13/drivers/clk/at91/pmc.h 2016-06-22 21:55:07.998523867 +0200
  7171. @@ -14,8 +14,11 @@
  7172. #include <linux/io.h>
  7173. #include <linux/irqdomain.h>
  7174. +#include <linux/regmap.h>
  7175. #include <linux/spinlock.h>
  7176. +extern spinlock_t pmc_pcr_lock;
  7177. +
  7178. struct clk_range {
  7179. unsigned long min;
  7180. unsigned long max;
  7181. @@ -23,102 +26,7 @@
  7182. #define CLK_RANGE(MIN, MAX) {.min = MIN, .max = MAX,}
  7183. -struct at91_pmc_caps {
  7184. - u32 available_irqs;
  7185. -};
  7186. -
  7187. -struct at91_pmc {
  7188. - void __iomem *regbase;
  7189. - int virq;
  7190. - spinlock_t lock;
  7191. - const struct at91_pmc_caps *caps;
  7192. - struct irq_domain *irqdomain;
  7193. - u32 imr;
  7194. -};
  7195. -
  7196. -static inline void pmc_lock(struct at91_pmc *pmc)
  7197. -{
  7198. - spin_lock(&pmc->lock);
  7199. -}
  7200. -
  7201. -static inline void pmc_unlock(struct at91_pmc *pmc)
  7202. -{
  7203. - spin_unlock(&pmc->lock);
  7204. -}
  7205. -
  7206. -static inline u32 pmc_read(struct at91_pmc *pmc, int offset)
  7207. -{
  7208. - return readl(pmc->regbase + offset);
  7209. -}
  7210. -
  7211. -static inline void pmc_write(struct at91_pmc *pmc, int offset, u32 value)
  7212. -{
  7213. - writel(value, pmc->regbase + offset);
  7214. -}
  7215. -
  7216. int of_at91_get_clk_range(struct device_node *np, const char *propname,
  7217. struct clk_range *range);
  7218. -void of_at91sam9260_clk_slow_setup(struct device_node *np,
  7219. - struct at91_pmc *pmc);
  7220. -
  7221. -void of_at91rm9200_clk_main_osc_setup(struct device_node *np,
  7222. - struct at91_pmc *pmc);
  7223. -void of_at91sam9x5_clk_main_rc_osc_setup(struct device_node *np,
  7224. - struct at91_pmc *pmc);
  7225. -void of_at91rm9200_clk_main_setup(struct device_node *np,
  7226. - struct at91_pmc *pmc);
  7227. -void of_at91sam9x5_clk_main_setup(struct device_node *np,
  7228. - struct at91_pmc *pmc);
  7229. -
  7230. -void of_at91rm9200_clk_pll_setup(struct device_node *np,
  7231. - struct at91_pmc *pmc);
  7232. -void of_at91sam9g45_clk_pll_setup(struct device_node *np,
  7233. - struct at91_pmc *pmc);
  7234. -void of_at91sam9g20_clk_pllb_setup(struct device_node *np,
  7235. - struct at91_pmc *pmc);
  7236. -void of_sama5d3_clk_pll_setup(struct device_node *np,
  7237. - struct at91_pmc *pmc);
  7238. -void of_at91sam9x5_clk_plldiv_setup(struct device_node *np,
  7239. - struct at91_pmc *pmc);
  7240. -
  7241. -void of_at91rm9200_clk_master_setup(struct device_node *np,
  7242. - struct at91_pmc *pmc);
  7243. -void of_at91sam9x5_clk_master_setup(struct device_node *np,
  7244. - struct at91_pmc *pmc);
  7245. -
  7246. -void of_at91rm9200_clk_sys_setup(struct device_node *np,
  7247. - struct at91_pmc *pmc);
  7248. -
  7249. -void of_at91rm9200_clk_periph_setup(struct device_node *np,
  7250. - struct at91_pmc *pmc);
  7251. -void of_at91sam9x5_clk_periph_setup(struct device_node *np,
  7252. - struct at91_pmc *pmc);
  7253. -
  7254. -void of_at91rm9200_clk_prog_setup(struct device_node *np,
  7255. - struct at91_pmc *pmc);
  7256. -void of_at91sam9g45_clk_prog_setup(struct device_node *np,
  7257. - struct at91_pmc *pmc);
  7258. -void of_at91sam9x5_clk_prog_setup(struct device_node *np,
  7259. - struct at91_pmc *pmc);
  7260. -
  7261. -void of_at91sam9x5_clk_utmi_setup(struct device_node *np,
  7262. - struct at91_pmc *pmc);
  7263. -
  7264. -void of_at91rm9200_clk_usb_setup(struct device_node *np,
  7265. - struct at91_pmc *pmc);
  7266. -void of_at91sam9x5_clk_usb_setup(struct device_node *np,
  7267. - struct at91_pmc *pmc);
  7268. -void of_at91sam9n12_clk_usb_setup(struct device_node *np,
  7269. - struct at91_pmc *pmc);
  7270. -
  7271. -void of_at91sam9x5_clk_smd_setup(struct device_node *np,
  7272. - struct at91_pmc *pmc);
  7273. -
  7274. -void of_sama5d4_clk_h32mx_setup(struct device_node *np,
  7275. - struct at91_pmc *pmc);
  7276. -
  7277. -void of_sama5d2_clk_generated_setup(struct device_node *np,
  7278. - struct at91_pmc *pmc);
  7279. -
  7280. #endif /* __PMC_H_ */
  7281. diff -Nur linux-4.4.13.orig/drivers/clocksource/tcb_clksrc.c linux-4.4.13/drivers/clocksource/tcb_clksrc.c
  7282. --- linux-4.4.13.orig/drivers/clocksource/tcb_clksrc.c 2016-06-08 03:14:51.000000000 +0200
  7283. +++ linux-4.4.13/drivers/clocksource/tcb_clksrc.c 2016-06-22 21:55:07.998523867 +0200
  7284. @@ -23,8 +23,7 @@
  7285. * this 32 bit free-running counter. the second channel is not used.
  7286. *
  7287. * - The third channel may be used to provide a 16-bit clockevent
  7288. - * source, used in either periodic or oneshot mode. This runs
  7289. - * at 32 KiHZ, and can handle delays of up to two seconds.
  7290. + * source, used in either periodic or oneshot mode.
  7291. *
  7292. * A boot clocksource and clockevent source are also currently needed,
  7293. * unless the relevant platforms (ARM/AT91, AVR32/AT32) are changed so
  7294. @@ -74,6 +73,8 @@
  7295. struct tc_clkevt_device {
  7296. struct clock_event_device clkevt;
  7297. struct clk *clk;
  7298. + bool clk_enabled;
  7299. + u32 freq;
  7300. void __iomem *regs;
  7301. };
  7302. @@ -82,15 +83,26 @@
  7303. return container_of(clkevt, struct tc_clkevt_device, clkevt);
  7304. }
  7305. -/* For now, we always use the 32K clock ... this optimizes for NO_HZ,
  7306. - * because using one of the divided clocks would usually mean the
  7307. - * tick rate can never be less than several dozen Hz (vs 0.5 Hz).
  7308. - *
  7309. - * A divided clock could be good for high resolution timers, since
  7310. - * 30.5 usec resolution can seem "low".
  7311. - */
  7312. static u32 timer_clock;
  7313. +static void tc_clk_disable(struct clock_event_device *d)
  7314. +{
  7315. + struct tc_clkevt_device *tcd = to_tc_clkevt(d);
  7316. +
  7317. + clk_disable(tcd->clk);
  7318. + tcd->clk_enabled = false;
  7319. +}
  7320. +
  7321. +static void tc_clk_enable(struct clock_event_device *d)
  7322. +{
  7323. + struct tc_clkevt_device *tcd = to_tc_clkevt(d);
  7324. +
  7325. + if (tcd->clk_enabled)
  7326. + return;
  7327. + clk_enable(tcd->clk);
  7328. + tcd->clk_enabled = true;
  7329. +}
  7330. +
  7331. static int tc_shutdown(struct clock_event_device *d)
  7332. {
  7333. struct tc_clkevt_device *tcd = to_tc_clkevt(d);
  7334. @@ -98,8 +110,14 @@
  7335. __raw_writel(0xff, regs + ATMEL_TC_REG(2, IDR));
  7336. __raw_writel(ATMEL_TC_CLKDIS, regs + ATMEL_TC_REG(2, CCR));
  7337. + return 0;
  7338. +}
  7339. +
  7340. +static int tc_shutdown_clk_off(struct clock_event_device *d)
  7341. +{
  7342. + tc_shutdown(d);
  7343. if (!clockevent_state_detached(d))
  7344. - clk_disable(tcd->clk);
  7345. + tc_clk_disable(d);
  7346. return 0;
  7347. }
  7348. @@ -112,9 +130,9 @@
  7349. if (clockevent_state_oneshot(d) || clockevent_state_periodic(d))
  7350. tc_shutdown(d);
  7351. - clk_enable(tcd->clk);
  7352. + tc_clk_enable(d);
  7353. - /* slow clock, count up to RC, then irq and stop */
  7354. + /* count up to RC, then irq and stop */
  7355. __raw_writel(timer_clock | ATMEL_TC_CPCSTOP | ATMEL_TC_WAVE |
  7356. ATMEL_TC_WAVESEL_UP_AUTO, regs + ATMEL_TC_REG(2, CMR));
  7357. __raw_writel(ATMEL_TC_CPCS, regs + ATMEL_TC_REG(2, IER));
  7358. @@ -134,12 +152,12 @@
  7359. /* By not making the gentime core emulate periodic mode on top
  7360. * of oneshot, we get lower overhead and improved accuracy.
  7361. */
  7362. - clk_enable(tcd->clk);
  7363. + tc_clk_enable(d);
  7364. - /* slow clock, count up to RC, then irq and restart */
  7365. + /* count up to RC, then irq and restart */
  7366. __raw_writel(timer_clock | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO,
  7367. regs + ATMEL_TC_REG(2, CMR));
  7368. - __raw_writel((32768 + HZ / 2) / HZ, tcaddr + ATMEL_TC_REG(2, RC));
  7369. + __raw_writel((tcd->freq + HZ / 2) / HZ, tcaddr + ATMEL_TC_REG(2, RC));
  7370. /* Enable clock and interrupts on RC compare */
  7371. __raw_writel(ATMEL_TC_CPCS, regs + ATMEL_TC_REG(2, IER));
  7372. @@ -166,9 +184,13 @@
  7373. .features = CLOCK_EVT_FEAT_PERIODIC |
  7374. CLOCK_EVT_FEAT_ONESHOT,
  7375. /* Should be lower than at91rm9200's system timer */
  7376. +#ifdef CONFIG_ATMEL_TCB_CLKSRC_USE_SLOW_CLOCK
  7377. .rating = 125,
  7378. +#else
  7379. + .rating = 200,
  7380. +#endif
  7381. .set_next_event = tc_next_event,
  7382. - .set_state_shutdown = tc_shutdown,
  7383. + .set_state_shutdown = tc_shutdown_clk_off,
  7384. .set_state_periodic = tc_set_periodic,
  7385. .set_state_oneshot = tc_set_oneshot,
  7386. },
  7387. @@ -188,8 +210,9 @@
  7388. return IRQ_NONE;
  7389. }
  7390. -static int __init setup_clkevents(struct atmel_tc *tc, int clk32k_divisor_idx)
  7391. +static int __init setup_clkevents(struct atmel_tc *tc, int divisor_idx)
  7392. {
  7393. + unsigned divisor = atmel_tc_divisors[divisor_idx];
  7394. int ret;
  7395. struct clk *t2_clk = tc->clk[2];
  7396. int irq = tc->irq[2];
  7397. @@ -210,7 +233,11 @@
  7398. clkevt.regs = tc->regs;
  7399. clkevt.clk = t2_clk;
  7400. - timer_clock = clk32k_divisor_idx;
  7401. + timer_clock = divisor_idx;
  7402. + if (!divisor)
  7403. + clkevt.freq = 32768;
  7404. + else
  7405. + clkevt.freq = clk_get_rate(t2_clk) / divisor;
  7406. clkevt.clkevt.cpumask = cpumask_of(0);
  7407. @@ -221,7 +248,7 @@
  7408. return ret;
  7409. }
  7410. - clockevents_config_and_register(&clkevt.clkevt, 32768, 1, 0xffff);
  7411. + clockevents_config_and_register(&clkevt.clkevt, clkevt.freq, 1, 0xffff);
  7412. return ret;
  7413. }
  7414. @@ -358,7 +385,11 @@
  7415. goto err_disable_t1;
  7416. /* channel 2: periodic and oneshot timer support */
  7417. +#ifdef CONFIG_ATMEL_TCB_CLKSRC_USE_SLOW_CLOCK
  7418. ret = setup_clkevents(tc, clk32k_divisor_idx);
  7419. +#else
  7420. + ret = setup_clkevents(tc, best_divisor_idx);
  7421. +#endif
  7422. if (ret)
  7423. goto err_unregister_clksrc;
  7424. diff -Nur linux-4.4.13.orig/drivers/clocksource/timer-atmel-pit.c linux-4.4.13/drivers/clocksource/timer-atmel-pit.c
  7425. --- linux-4.4.13.orig/drivers/clocksource/timer-atmel-pit.c 2016-06-08 03:14:51.000000000 +0200
  7426. +++ linux-4.4.13/drivers/clocksource/timer-atmel-pit.c 2016-06-22 21:55:07.998523867 +0200
  7427. @@ -46,6 +46,7 @@
  7428. u32 cycle;
  7429. u32 cnt;
  7430. unsigned int irq;
  7431. + bool irq_requested;
  7432. struct clk *mck;
  7433. };
  7434. @@ -96,15 +97,29 @@
  7435. /* disable irq, leaving the clocksource active */
  7436. pit_write(data->base, AT91_PIT_MR, (data->cycle - 1) | AT91_PIT_PITEN);
  7437. + if (data->irq_requested) {
  7438. + free_irq(data->irq, data);
  7439. + data->irq_requested = false;
  7440. + }
  7441. return 0;
  7442. }
  7443. +static irqreturn_t at91sam926x_pit_interrupt(int irq, void *dev_id);
  7444. /*
  7445. * Clockevent device: interrupts every 1/HZ (== pit_cycles * MCK/16)
  7446. */
  7447. static int pit_clkevt_set_periodic(struct clock_event_device *dev)
  7448. {
  7449. struct pit_data *data = clkevt_to_pit_data(dev);
  7450. + int ret;
  7451. +
  7452. + ret = request_irq(data->irq, at91sam926x_pit_interrupt,
  7453. + IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
  7454. + "at91_tick", data);
  7455. + if (ret)
  7456. + panic(pr_fmt("Unable to setup IRQ\n"));
  7457. +
  7458. + data->irq_requested = true;
  7459. /* update clocksource counter */
  7460. data->cnt += data->cycle * PIT_PICNT(pit_read(data->base, AT91_PIT_PIVR));
  7461. @@ -181,7 +196,6 @@
  7462. {
  7463. unsigned long pit_rate;
  7464. unsigned bits;
  7465. - int ret;
  7466. /*
  7467. * Use our actual MCK to figure out how many MCK/16 ticks per
  7468. @@ -206,13 +220,6 @@
  7469. data->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
  7470. clocksource_register_hz(&data->clksrc, pit_rate);
  7471. - /* Set up irq handler */
  7472. - ret = request_irq(data->irq, at91sam926x_pit_interrupt,
  7473. - IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
  7474. - "at91_tick", data);
  7475. - if (ret)
  7476. - panic(pr_fmt("Unable to setup IRQ\n"));
  7477. -
  7478. /* Set up and register clockevents */
  7479. data->clkevt.name = "pit";
  7480. data->clkevt.features = CLOCK_EVT_FEAT_PERIODIC;
  7481. diff -Nur linux-4.4.13.orig/drivers/clocksource/timer-atmel-st.c linux-4.4.13/drivers/clocksource/timer-atmel-st.c
  7482. --- linux-4.4.13.orig/drivers/clocksource/timer-atmel-st.c 2016-06-08 03:14:51.000000000 +0200
  7483. +++ linux-4.4.13/drivers/clocksource/timer-atmel-st.c 2016-06-22 21:55:07.998523867 +0200
  7484. @@ -115,18 +115,29 @@
  7485. last_crtr = read_CRTR();
  7486. }
  7487. +static int atmel_st_irq;
  7488. +
  7489. static int clkevt32k_shutdown(struct clock_event_device *evt)
  7490. {
  7491. clkdev32k_disable_and_flush_irq();
  7492. irqmask = 0;
  7493. regmap_write(regmap_st, AT91_ST_IER, irqmask);
  7494. + free_irq(atmel_st_irq, regmap_st);
  7495. return 0;
  7496. }
  7497. static int clkevt32k_set_oneshot(struct clock_event_device *dev)
  7498. {
  7499. + int ret;
  7500. +
  7501. clkdev32k_disable_and_flush_irq();
  7502. + ret = request_irq(atmel_st_irq, at91rm9200_timer_interrupt,
  7503. + IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
  7504. + "at91_tick", regmap_st);
  7505. + if (ret)
  7506. + panic(pr_fmt("Unable to setup IRQ\n"));
  7507. +
  7508. /*
  7509. * ALM for oneshot irqs, set by next_event()
  7510. * before 32 seconds have passed.
  7511. @@ -139,8 +150,16 @@
  7512. static int clkevt32k_set_periodic(struct clock_event_device *dev)
  7513. {
  7514. + int ret;
  7515. +
  7516. clkdev32k_disable_and_flush_irq();
  7517. + ret = request_irq(atmel_st_irq, at91rm9200_timer_interrupt,
  7518. + IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
  7519. + "at91_tick", regmap_st);
  7520. + if (ret)
  7521. + panic(pr_fmt("Unable to setup IRQ\n"));
  7522. +
  7523. /* PIT for periodic irqs; fixed rate of 1/HZ */
  7524. irqmask = AT91_ST_PITS;
  7525. regmap_write(regmap_st, AT91_ST_PIMR, timer_latch);
  7526. @@ -198,7 +217,7 @@
  7527. {
  7528. struct clk *sclk;
  7529. unsigned int sclk_rate, val;
  7530. - int irq, ret;
  7531. + int ret;
  7532. regmap_st = syscon_node_to_regmap(node);
  7533. if (IS_ERR(regmap_st))
  7534. @@ -210,17 +229,10 @@
  7535. regmap_read(regmap_st, AT91_ST_SR, &val);
  7536. /* Get the interrupts property */
  7537. - irq = irq_of_parse_and_map(node, 0);
  7538. - if (!irq)
  7539. + atmel_st_irq = irq_of_parse_and_map(node, 0);
  7540. + if (!atmel_st_irq)
  7541. panic(pr_fmt("Unable to get IRQ from DT\n"));
  7542. - /* Make IRQs happen for the system timer */
  7543. - ret = request_irq(irq, at91rm9200_timer_interrupt,
  7544. - IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
  7545. - "at91_tick", regmap_st);
  7546. - if (ret)
  7547. - panic(pr_fmt("Unable to setup IRQ\n"));
  7548. -
  7549. sclk = of_clk_get(node, 0);
  7550. if (IS_ERR(sclk))
  7551. panic(pr_fmt("Unable to get slow clock\n"));
  7552. diff -Nur linux-4.4.13.orig/drivers/cpufreq/Kconfig.x86 linux-4.4.13/drivers/cpufreq/Kconfig.x86
  7553. --- linux-4.4.13.orig/drivers/cpufreq/Kconfig.x86 2016-06-08 03:14:51.000000000 +0200
  7554. +++ linux-4.4.13/drivers/cpufreq/Kconfig.x86 2016-06-22 21:55:07.998523867 +0200
  7555. @@ -123,7 +123,7 @@
  7556. config X86_POWERNOW_K8
  7557. tristate "AMD Opteron/Athlon64 PowerNow!"
  7558. - depends on ACPI && ACPI_PROCESSOR && X86_ACPI_CPUFREQ
  7559. + depends on ACPI && ACPI_PROCESSOR && X86_ACPI_CPUFREQ && !PREEMPT_RT_BASE
  7560. help
  7561. This adds the CPUFreq driver for K8/early Opteron/Athlon64 processors.
  7562. Support for K10 and newer processors is now in acpi-cpufreq.
  7563. diff -Nur linux-4.4.13.orig/drivers/cpuidle/coupled.c linux-4.4.13/drivers/cpuidle/coupled.c
  7564. --- linux-4.4.13.orig/drivers/cpuidle/coupled.c 2016-06-08 03:14:51.000000000 +0200
  7565. +++ linux-4.4.13/drivers/cpuidle/coupled.c 2016-06-22 21:55:07.998523867 +0200
  7566. @@ -119,7 +119,6 @@
  7567. #define CPUIDLE_COUPLED_NOT_IDLE (-1)
  7568. -static DEFINE_MUTEX(cpuidle_coupled_lock);
  7569. static DEFINE_PER_CPU(struct call_single_data, cpuidle_coupled_poke_cb);
  7570. /*
  7571. diff -Nur linux-4.4.13.orig/drivers/gpu/drm/i915/i915_gem_execbuffer.c linux-4.4.13/drivers/gpu/drm/i915/i915_gem_execbuffer.c
  7572. --- linux-4.4.13.orig/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2016-06-08 03:14:51.000000000 +0200
  7573. +++ linux-4.4.13/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2016-06-22 21:55:07.998523867 +0200
  7574. @@ -1264,7 +1264,9 @@
  7575. if (ret)
  7576. return ret;
  7577. +#ifndef CONFIG_PREEMPT_RT_BASE
  7578. trace_i915_gem_ring_dispatch(params->request, params->dispatch_flags);
  7579. +#endif
  7580. i915_gem_execbuffer_move_to_active(vmas, params->request);
  7581. i915_gem_execbuffer_retire_commands(params);
  7582. diff -Nur linux-4.4.13.orig/drivers/gpu/drm/i915/i915_gem_shrinker.c linux-4.4.13/drivers/gpu/drm/i915/i915_gem_shrinker.c
  7583. --- linux-4.4.13.orig/drivers/gpu/drm/i915/i915_gem_shrinker.c 2016-06-08 03:14:51.000000000 +0200
  7584. +++ linux-4.4.13/drivers/gpu/drm/i915/i915_gem_shrinker.c 2016-06-22 21:55:07.998523867 +0200
  7585. @@ -39,7 +39,7 @@
  7586. if (!mutex_is_locked(mutex))
  7587. return false;
  7588. -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_MUTEXES)
  7589. +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_MUTEXES)) && !defined(CONFIG_PREEMPT_RT_BASE)
  7590. return mutex->owner == task;
  7591. #else
  7592. /* Since UP may be pre-empted, we cannot assume that we own the lock */
  7593. diff -Nur linux-4.4.13.orig/drivers/gpu/drm/i915/i915_irq.c linux-4.4.13/drivers/gpu/drm/i915/i915_irq.c
  7594. --- linux-4.4.13.orig/drivers/gpu/drm/i915/i915_irq.c 2016-06-08 03:14:51.000000000 +0200
  7595. +++ linux-4.4.13/drivers/gpu/drm/i915/i915_irq.c 2016-06-22 21:55:08.002523867 +0200
  7596. @@ -812,6 +812,7 @@
  7597. spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
  7598. /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
  7599. + preempt_disable_rt();
  7600. /* Get optional system timestamp before query. */
  7601. if (stime)
  7602. @@ -863,6 +864,7 @@
  7603. *etime = ktime_get();
  7604. /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
  7605. + preempt_enable_rt();
  7606. spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
  7607. diff -Nur linux-4.4.13.orig/drivers/gpu/drm/i915/intel_display.c linux-4.4.13/drivers/gpu/drm/i915/intel_display.c
  7608. --- linux-4.4.13.orig/drivers/gpu/drm/i915/intel_display.c 2016-06-08 03:14:51.000000000 +0200
  7609. +++ linux-4.4.13/drivers/gpu/drm/i915/intel_display.c 2016-06-22 21:55:08.002523867 +0200
  7610. @@ -11376,7 +11376,7 @@
  7611. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  7612. struct intel_unpin_work *work;
  7613. - WARN_ON(!in_interrupt());
  7614. + WARN_ON_NONRT(!in_interrupt());
  7615. if (crtc == NULL)
  7616. return;
  7617. diff -Nur linux-4.4.13.orig/drivers/gpu/drm/i915/intel_sprite.c linux-4.4.13/drivers/gpu/drm/i915/intel_sprite.c
  7618. --- linux-4.4.13.orig/drivers/gpu/drm/i915/intel_sprite.c 2016-06-08 03:14:51.000000000 +0200
  7619. +++ linux-4.4.13/drivers/gpu/drm/i915/intel_sprite.c 2016-06-22 21:55:08.002523867 +0200
  7620. @@ -38,6 +38,7 @@
  7621. #include "intel_drv.h"
  7622. #include <drm/i915_drm.h>
  7623. #include "i915_drv.h"
  7624. +#include <linux/locallock.h>
  7625. static bool
  7626. format_is_yuv(uint32_t format)
  7627. @@ -64,6 +65,8 @@
  7628. 1000 * adjusted_mode->crtc_htotal);
  7629. }
  7630. +static DEFINE_LOCAL_IRQ_LOCK(pipe_update_lock);
  7631. +
  7632. /**
  7633. * intel_pipe_update_start() - start update of a set of display registers
  7634. * @crtc: the crtc of which the registers are going to be updated
  7635. @@ -96,7 +99,7 @@
  7636. min = vblank_start - usecs_to_scanlines(adjusted_mode, 100);
  7637. max = vblank_start - 1;
  7638. - local_irq_disable();
  7639. + local_lock_irq(pipe_update_lock);
  7640. if (min <= 0 || max <= 0)
  7641. return;
  7642. @@ -126,11 +129,11 @@
  7643. break;
  7644. }
  7645. - local_irq_enable();
  7646. + local_unlock_irq(pipe_update_lock);
  7647. timeout = schedule_timeout(timeout);
  7648. - local_irq_disable();
  7649. + local_lock_irq(pipe_update_lock);
  7650. }
  7651. finish_wait(wq, &wait);
  7652. @@ -164,7 +167,7 @@
  7653. trace_i915_pipe_update_end(crtc, end_vbl_count, scanline_end);
  7654. - local_irq_enable();
  7655. + local_unlock_irq(pipe_update_lock);
  7656. if (crtc->debug.start_vbl_count &&
  7657. crtc->debug.start_vbl_count != end_vbl_count) {
  7658. diff -Nur linux-4.4.13.orig/drivers/gpu/drm/radeon/radeon_display.c linux-4.4.13/drivers/gpu/drm/radeon/radeon_display.c
  7659. --- linux-4.4.13.orig/drivers/gpu/drm/radeon/radeon_display.c 2016-06-08 03:14:51.000000000 +0200
  7660. +++ linux-4.4.13/drivers/gpu/drm/radeon/radeon_display.c 2016-06-22 21:55:08.002523867 +0200
  7661. @@ -1862,6 +1862,7 @@
  7662. struct radeon_device *rdev = dev->dev_private;
  7663. /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
  7664. + preempt_disable_rt();
  7665. /* Get optional system timestamp before query. */
  7666. if (stime)
  7667. @@ -1954,6 +1955,7 @@
  7668. *etime = ktime_get();
  7669. /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
  7670. + preempt_enable_rt();
  7671. /* Decode into vertical and horizontal scanout position. */
  7672. *vpos = position & 0x1fff;
  7673. diff -Nur linux-4.4.13.orig/drivers/i2c/busses/i2c-omap.c linux-4.4.13/drivers/i2c/busses/i2c-omap.c
  7674. --- linux-4.4.13.orig/drivers/i2c/busses/i2c-omap.c 2016-06-08 03:14:51.000000000 +0200
  7675. +++ linux-4.4.13/drivers/i2c/busses/i2c-omap.c 2016-06-22 21:55:08.006523867 +0200
  7676. @@ -995,15 +995,12 @@
  7677. u16 mask;
  7678. u16 stat;
  7679. - spin_lock(&omap->lock);
  7680. - mask = omap_i2c_read_reg(omap, OMAP_I2C_IE_REG);
  7681. stat = omap_i2c_read_reg(omap, OMAP_I2C_STAT_REG);
  7682. + mask = omap_i2c_read_reg(omap, OMAP_I2C_IE_REG);
  7683. if (stat & mask)
  7684. ret = IRQ_WAKE_THREAD;
  7685. - spin_unlock(&omap->lock);
  7686. -
  7687. return ret;
  7688. }
  7689. diff -Nur linux-4.4.13.orig/drivers/ide/alim15x3.c linux-4.4.13/drivers/ide/alim15x3.c
  7690. --- linux-4.4.13.orig/drivers/ide/alim15x3.c 2016-06-08 03:14:51.000000000 +0200
  7691. +++ linux-4.4.13/drivers/ide/alim15x3.c 2016-06-22 21:55:08.006523867 +0200
  7692. @@ -234,7 +234,7 @@
  7693. isa_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  7694. - local_irq_save(flags);
  7695. + local_irq_save_nort(flags);
  7696. if (m5229_revision < 0xC2) {
  7697. /*
  7698. @@ -325,7 +325,7 @@
  7699. }
  7700. pci_dev_put(north);
  7701. pci_dev_put(isa_dev);
  7702. - local_irq_restore(flags);
  7703. + local_irq_restore_nort(flags);
  7704. return 0;
  7705. }
  7706. diff -Nur linux-4.4.13.orig/drivers/ide/hpt366.c linux-4.4.13/drivers/ide/hpt366.c
  7707. --- linux-4.4.13.orig/drivers/ide/hpt366.c 2016-06-08 03:14:51.000000000 +0200
  7708. +++ linux-4.4.13/drivers/ide/hpt366.c 2016-06-22 21:55:08.006523867 +0200
  7709. @@ -1241,7 +1241,7 @@
  7710. dma_old = inb(base + 2);
  7711. - local_irq_save(flags);
  7712. + local_irq_save_nort(flags);
  7713. dma_new = dma_old;
  7714. pci_read_config_byte(dev, hwif->channel ? 0x4b : 0x43, &masterdma);
  7715. @@ -1252,7 +1252,7 @@
  7716. if (dma_new != dma_old)
  7717. outb(dma_new, base + 2);
  7718. - local_irq_restore(flags);
  7719. + local_irq_restore_nort(flags);
  7720. printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx\n",
  7721. hwif->name, base, base + 7);
  7722. diff -Nur linux-4.4.13.orig/drivers/ide/ide-io.c linux-4.4.13/drivers/ide/ide-io.c
  7723. --- linux-4.4.13.orig/drivers/ide/ide-io.c 2016-06-08 03:14:51.000000000 +0200
  7724. +++ linux-4.4.13/drivers/ide/ide-io.c 2016-06-22 21:55:08.006523867 +0200
  7725. @@ -659,7 +659,7 @@
  7726. /* disable_irq_nosync ?? */
  7727. disable_irq(hwif->irq);
  7728. /* local CPU only, as if we were handling an interrupt */
  7729. - local_irq_disable();
  7730. + local_irq_disable_nort();
  7731. if (hwif->polling) {
  7732. startstop = handler(drive);
  7733. } else if (drive_is_ready(drive)) {
  7734. diff -Nur linux-4.4.13.orig/drivers/ide/ide-iops.c linux-4.4.13/drivers/ide/ide-iops.c
  7735. --- linux-4.4.13.orig/drivers/ide/ide-iops.c 2016-06-08 03:14:51.000000000 +0200
  7736. +++ linux-4.4.13/drivers/ide/ide-iops.c 2016-06-22 21:55:08.006523867 +0200
  7737. @@ -129,12 +129,12 @@
  7738. if ((stat & ATA_BUSY) == 0)
  7739. break;
  7740. - local_irq_restore(flags);
  7741. + local_irq_restore_nort(flags);
  7742. *rstat = stat;
  7743. return -EBUSY;
  7744. }
  7745. }
  7746. - local_irq_restore(flags);
  7747. + local_irq_restore_nort(flags);
  7748. }
  7749. /*
  7750. * Allow status to settle, then read it again.
  7751. diff -Nur linux-4.4.13.orig/drivers/ide/ide-io-std.c linux-4.4.13/drivers/ide/ide-io-std.c
  7752. --- linux-4.4.13.orig/drivers/ide/ide-io-std.c 2016-06-08 03:14:51.000000000 +0200
  7753. +++ linux-4.4.13/drivers/ide/ide-io-std.c 2016-06-22 21:55:08.006523867 +0200
  7754. @@ -175,7 +175,7 @@
  7755. unsigned long uninitialized_var(flags);
  7756. if ((io_32bit & 2) && !mmio) {
  7757. - local_irq_save(flags);
  7758. + local_irq_save_nort(flags);
  7759. ata_vlb_sync(io_ports->nsect_addr);
  7760. }
  7761. @@ -186,7 +186,7 @@
  7762. insl(data_addr, buf, words);
  7763. if ((io_32bit & 2) && !mmio)
  7764. - local_irq_restore(flags);
  7765. + local_irq_restore_nort(flags);
  7766. if (((len + 1) & 3) < 2)
  7767. return;
  7768. @@ -219,7 +219,7 @@
  7769. unsigned long uninitialized_var(flags);
  7770. if ((io_32bit & 2) && !mmio) {
  7771. - local_irq_save(flags);
  7772. + local_irq_save_nort(flags);
  7773. ata_vlb_sync(io_ports->nsect_addr);
  7774. }
  7775. @@ -230,7 +230,7 @@
  7776. outsl(data_addr, buf, words);
  7777. if ((io_32bit & 2) && !mmio)
  7778. - local_irq_restore(flags);
  7779. + local_irq_restore_nort(flags);
  7780. if (((len + 1) & 3) < 2)
  7781. return;
  7782. diff -Nur linux-4.4.13.orig/drivers/ide/ide-probe.c linux-4.4.13/drivers/ide/ide-probe.c
  7783. --- linux-4.4.13.orig/drivers/ide/ide-probe.c 2016-06-08 03:14:51.000000000 +0200
  7784. +++ linux-4.4.13/drivers/ide/ide-probe.c 2016-06-22 21:55:08.006523867 +0200
  7785. @@ -196,10 +196,10 @@
  7786. int bswap = 1;
  7787. /* local CPU only; some systems need this */
  7788. - local_irq_save(flags);
  7789. + local_irq_save_nort(flags);
  7790. /* read 512 bytes of id info */
  7791. hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE);
  7792. - local_irq_restore(flags);
  7793. + local_irq_restore_nort(flags);
  7794. drive->dev_flags |= IDE_DFLAG_ID_READ;
  7795. #ifdef DEBUG
  7796. diff -Nur linux-4.4.13.orig/drivers/ide/ide-taskfile.c linux-4.4.13/drivers/ide/ide-taskfile.c
  7797. --- linux-4.4.13.orig/drivers/ide/ide-taskfile.c 2016-06-08 03:14:51.000000000 +0200
  7798. +++ linux-4.4.13/drivers/ide/ide-taskfile.c 2016-06-22 21:55:08.006523867 +0200
  7799. @@ -250,7 +250,7 @@
  7800. page_is_high = PageHighMem(page);
  7801. if (page_is_high)
  7802. - local_irq_save(flags);
  7803. + local_irq_save_nort(flags);
  7804. buf = kmap_atomic(page) + offset;
  7805. @@ -271,7 +271,7 @@
  7806. kunmap_atomic(buf);
  7807. if (page_is_high)
  7808. - local_irq_restore(flags);
  7809. + local_irq_restore_nort(flags);
  7810. len -= nr_bytes;
  7811. }
  7812. @@ -414,7 +414,7 @@
  7813. }
  7814. if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
  7815. - local_irq_disable();
  7816. + local_irq_disable_nort();
  7817. ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
  7818. diff -Nur linux-4.4.13.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c linux-4.4.13/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
  7819. --- linux-4.4.13.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2016-06-08 03:14:51.000000000 +0200
  7820. +++ linux-4.4.13/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2016-06-22 21:55:08.006523867 +0200
  7821. @@ -857,7 +857,7 @@
  7822. ipoib_dbg_mcast(priv, "restarting multicast task\n");
  7823. - local_irq_save(flags);
  7824. + local_irq_save_nort(flags);
  7825. netif_addr_lock(dev);
  7826. spin_lock(&priv->lock);
  7827. @@ -939,7 +939,7 @@
  7828. spin_unlock(&priv->lock);
  7829. netif_addr_unlock(dev);
  7830. - local_irq_restore(flags);
  7831. + local_irq_restore_nort(flags);
  7832. /*
  7833. * make sure the in-flight joins have finished before we attempt
  7834. diff -Nur linux-4.4.13.orig/drivers/input/gameport/gameport.c linux-4.4.13/drivers/input/gameport/gameport.c
  7835. --- linux-4.4.13.orig/drivers/input/gameport/gameport.c 2016-06-08 03:14:51.000000000 +0200
  7836. +++ linux-4.4.13/drivers/input/gameport/gameport.c 2016-06-22 21:55:08.006523867 +0200
  7837. @@ -91,13 +91,13 @@
  7838. tx = ~0;
  7839. for (i = 0; i < 50; i++) {
  7840. - local_irq_save(flags);
  7841. + local_irq_save_nort(flags);
  7842. t1 = ktime_get_ns();
  7843. for (t = 0; t < 50; t++)
  7844. gameport_read(gameport);
  7845. t2 = ktime_get_ns();
  7846. t3 = ktime_get_ns();
  7847. - local_irq_restore(flags);
  7848. + local_irq_restore_nort(flags);
  7849. udelay(i * 10);
  7850. t = (t2 - t1) - (t3 - t2);
  7851. if (t < tx)
  7852. @@ -124,12 +124,12 @@
  7853. tx = 1 << 30;
  7854. for(i = 0; i < 50; i++) {
  7855. - local_irq_save(flags);
  7856. + local_irq_save_nort(flags);
  7857. GET_TIME(t1);
  7858. for (t = 0; t < 50; t++) gameport_read(gameport);
  7859. GET_TIME(t2);
  7860. GET_TIME(t3);
  7861. - local_irq_restore(flags);
  7862. + local_irq_restore_nort(flags);
  7863. udelay(i * 10);
  7864. if ((t = DELTA(t2,t1) - DELTA(t3,t2)) < tx) tx = t;
  7865. }
  7866. @@ -148,11 +148,11 @@
  7867. tx = 1 << 30;
  7868. for(i = 0; i < 50; i++) {
  7869. - local_irq_save(flags);
  7870. + local_irq_save_nort(flags);
  7871. t1 = rdtsc();
  7872. for (t = 0; t < 50; t++) gameport_read(gameport);
  7873. t2 = rdtsc();
  7874. - local_irq_restore(flags);
  7875. + local_irq_restore_nort(flags);
  7876. udelay(i * 10);
  7877. if (t2 - t1 < tx) tx = t2 - t1;
  7878. }
  7879. diff -Nur linux-4.4.13.orig/drivers/iommu/amd_iommu.c linux-4.4.13/drivers/iommu/amd_iommu.c
  7880. --- linux-4.4.13.orig/drivers/iommu/amd_iommu.c 2016-06-08 03:14:51.000000000 +0200
  7881. +++ linux-4.4.13/drivers/iommu/amd_iommu.c 2016-06-22 21:55:08.006523867 +0200
  7882. @@ -2017,10 +2017,10 @@
  7883. int ret;
  7884. /*
  7885. - * Must be called with IRQs disabled. Warn here to detect early
  7886. - * when its not.
  7887. + * Must be called with IRQs disabled on a non RT kernel. Warn here to
  7888. + * detect early when its not.
  7889. */
  7890. - WARN_ON(!irqs_disabled());
  7891. + WARN_ON_NONRT(!irqs_disabled());
  7892. /* lock domain */
  7893. spin_lock(&domain->lock);
  7894. @@ -2183,10 +2183,10 @@
  7895. struct protection_domain *domain;
  7896. /*
  7897. - * Must be called with IRQs disabled. Warn here to detect early
  7898. - * when its not.
  7899. + * Must be called with IRQs disabled on a non RT kernel. Warn here to
  7900. + * detect early when its not.
  7901. */
  7902. - WARN_ON(!irqs_disabled());
  7903. + WARN_ON_NONRT(!irqs_disabled());
  7904. if (WARN_ON(!dev_data->domain))
  7905. return;
  7906. diff -Nur linux-4.4.13.orig/drivers/leds/trigger/Kconfig linux-4.4.13/drivers/leds/trigger/Kconfig
  7907. --- linux-4.4.13.orig/drivers/leds/trigger/Kconfig 2016-06-08 03:14:51.000000000 +0200
  7908. +++ linux-4.4.13/drivers/leds/trigger/Kconfig 2016-06-22 21:55:08.006523867 +0200
  7909. @@ -61,7 +61,7 @@
  7910. config LEDS_TRIGGER_CPU
  7911. bool "LED CPU Trigger"
  7912. - depends on LEDS_TRIGGERS
  7913. + depends on LEDS_TRIGGERS && !PREEMPT_RT_BASE
  7914. help
  7915. This allows LEDs to be controlled by active CPUs. This shows
  7916. the active CPUs across an array of LEDs so you can see which
  7917. diff -Nur linux-4.4.13.orig/drivers/md/bcache/Kconfig linux-4.4.13/drivers/md/bcache/Kconfig
  7918. --- linux-4.4.13.orig/drivers/md/bcache/Kconfig 2016-06-08 03:14:51.000000000 +0200
  7919. +++ linux-4.4.13/drivers/md/bcache/Kconfig 2016-06-22 21:55:08.006523867 +0200
  7920. @@ -1,6 +1,7 @@
  7921. config BCACHE
  7922. tristate "Block device as cache"
  7923. + depends on !PREEMPT_RT_FULL
  7924. ---help---
  7925. Allows a block device to be used as cache for other devices; uses
  7926. a btree for indexing and the layout is optimized for SSDs.
  7927. diff -Nur linux-4.4.13.orig/drivers/md/dm.c linux-4.4.13/drivers/md/dm.c
  7928. --- linux-4.4.13.orig/drivers/md/dm.c 2016-06-08 03:14:51.000000000 +0200
  7929. +++ linux-4.4.13/drivers/md/dm.c 2016-06-22 21:55:08.006523867 +0200
  7930. @@ -2127,7 +2127,7 @@
  7931. /* Establish tio->ti before queuing work (map_tio_request) */
  7932. tio->ti = ti;
  7933. queue_kthread_work(&md->kworker, &tio->work);
  7934. - BUG_ON(!irqs_disabled());
  7935. + BUG_ON_NONRT(!irqs_disabled());
  7936. }
  7937. goto out;
  7938. diff -Nur linux-4.4.13.orig/drivers/md/raid5.c linux-4.4.13/drivers/md/raid5.c
  7939. --- linux-4.4.13.orig/drivers/md/raid5.c 2016-06-08 03:14:51.000000000 +0200
  7940. +++ linux-4.4.13/drivers/md/raid5.c 2016-06-22 21:55:08.010523867 +0200
  7941. @@ -1920,8 +1920,9 @@
  7942. struct raid5_percpu *percpu;
  7943. unsigned long cpu;
  7944. - cpu = get_cpu();
  7945. + cpu = get_cpu_light();
  7946. percpu = per_cpu_ptr(conf->percpu, cpu);
  7947. + spin_lock(&percpu->lock);
  7948. if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) {
  7949. ops_run_biofill(sh);
  7950. overlap_clear++;
  7951. @@ -1977,7 +1978,8 @@
  7952. if (test_and_clear_bit(R5_Overlap, &dev->flags))
  7953. wake_up(&sh->raid_conf->wait_for_overlap);
  7954. }
  7955. - put_cpu();
  7956. + spin_unlock(&percpu->lock);
  7957. + put_cpu_light();
  7958. }
  7959. static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp)
  7960. @@ -6414,6 +6416,7 @@
  7961. __func__, cpu);
  7962. break;
  7963. }
  7964. + spin_lock_init(&per_cpu_ptr(conf->percpu, cpu)->lock);
  7965. }
  7966. put_online_cpus();
  7967. diff -Nur linux-4.4.13.orig/drivers/md/raid5.h linux-4.4.13/drivers/md/raid5.h
  7968. --- linux-4.4.13.orig/drivers/md/raid5.h 2016-06-08 03:14:51.000000000 +0200
  7969. +++ linux-4.4.13/drivers/md/raid5.h 2016-06-22 21:55:08.010523867 +0200
  7970. @@ -504,6 +504,7 @@
  7971. int recovery_disabled;
  7972. /* per cpu variables */
  7973. struct raid5_percpu {
  7974. + spinlock_t lock; /* Protection for -RT */
  7975. struct page *spare_page; /* Used when checking P/Q in raid6 */
  7976. struct flex_array *scribble; /* space for constructing buffer
  7977. * lists and performing address
  7978. diff -Nur linux-4.4.13.orig/drivers/media/platform/vsp1/vsp1_video.c linux-4.4.13/drivers/media/platform/vsp1/vsp1_video.c
  7979. --- linux-4.4.13.orig/drivers/media/platform/vsp1/vsp1_video.c 2016-06-08 03:14:51.000000000 +0200
  7980. +++ linux-4.4.13/drivers/media/platform/vsp1/vsp1_video.c 2016-06-22 21:55:08.010523867 +0200
  7981. @@ -520,7 +520,7 @@
  7982. bool stopped;
  7983. spin_lock_irqsave(&pipe->irqlock, flags);
  7984. - stopped = pipe->state == VSP1_PIPELINE_STOPPED,
  7985. + stopped = pipe->state == VSP1_PIPELINE_STOPPED;
  7986. spin_unlock_irqrestore(&pipe->irqlock, flags);
  7987. return stopped;
  7988. diff -Nur linux-4.4.13.orig/drivers/misc/hwlat_detector.c linux-4.4.13/drivers/misc/hwlat_detector.c
  7989. --- linux-4.4.13.orig/drivers/misc/hwlat_detector.c 1970-01-01 01:00:00.000000000 +0100
  7990. +++ linux-4.4.13/drivers/misc/hwlat_detector.c 2016-06-22 21:55:08.010523867 +0200
  7991. @@ -0,0 +1,1240 @@
  7992. +/*
  7993. + * hwlat_detector.c - A simple Hardware Latency detector.
  7994. + *
  7995. + * Use this module to detect large system latencies induced by the behavior of
  7996. + * certain underlying system hardware or firmware, independent of Linux itself.
  7997. + * The code was developed originally to detect the presence of SMIs on Intel
  7998. + * and AMD systems, although there is no dependency upon x86 herein.
  7999. + *
  8000. + * The classical example usage of this module is in detecting the presence of
  8001. + * SMIs or System Management Interrupts on Intel and AMD systems. An SMI is a
  8002. + * somewhat special form of hardware interrupt spawned from earlier CPU debug
  8003. + * modes in which the (BIOS/EFI/etc.) firmware arranges for the South Bridge
  8004. + * LPC (or other device) to generate a special interrupt under certain
  8005. + * circumstances, for example, upon expiration of a special SMI timer device,
  8006. + * due to certain external thermal readings, on certain I/O address accesses,
  8007. + * and other situations. An SMI hits a special CPU pin, triggers a special
  8008. + * SMI mode (complete with special memory map), and the OS is unaware.
  8009. + *
  8010. + * Although certain hardware-inducing latencies are necessary (for example,
  8011. + * a modern system often requires an SMI handler for correct thermal control
  8012. + * and remote management) they can wreak havoc upon any OS-level performance
  8013. + * guarantees toward low-latency, especially when the OS is not even made
  8014. + * aware of the presence of these interrupts. For this reason, we need a
  8015. + * somewhat brute force mechanism to detect these interrupts. In this case,
  8016. + * we do it by hogging all of the CPU(s) for configurable timer intervals,
  8017. + * sampling the built-in CPU timer, looking for discontiguous readings.
  8018. + *
  8019. + * WARNING: This implementation necessarily introduces latencies. Therefore,
  8020. + * you should NEVER use this module in a production environment
  8021. + * requiring any kind of low-latency performance guarantee(s).
  8022. + *
  8023. + * Copyright (C) 2008-2009 Jon Masters, Red Hat, Inc. <jcm@redhat.com>
  8024. + *
  8025. + * Includes useful feedback from Clark Williams <clark@redhat.com>
  8026. + *
  8027. + * This file is licensed under the terms of the GNU General Public
  8028. + * License version 2. This program is licensed "as is" without any
  8029. + * warranty of any kind, whether express or implied.
  8030. + */
  8031. +
  8032. +#include <linux/module.h>
  8033. +#include <linux/init.h>
  8034. +#include <linux/ring_buffer.h>
  8035. +#include <linux/time.h>
  8036. +#include <linux/hrtimer.h>
  8037. +#include <linux/kthread.h>
  8038. +#include <linux/debugfs.h>
  8039. +#include <linux/seq_file.h>
  8040. +#include <linux/uaccess.h>
  8041. +#include <linux/version.h>
  8042. +#include <linux/delay.h>
  8043. +#include <linux/slab.h>
  8044. +#include <linux/trace_clock.h>
  8045. +
  8046. +#define BUF_SIZE_DEFAULT 262144UL /* 8K*(sizeof(entry)) */
  8047. +#define BUF_FLAGS (RB_FL_OVERWRITE) /* no block on full */
  8048. +#define U64STR_SIZE 22 /* 20 digits max */
  8049. +
  8050. +#define VERSION "1.0.0"
  8051. +#define BANNER "hwlat_detector: "
  8052. +#define DRVNAME "hwlat_detector"
  8053. +#define DEFAULT_SAMPLE_WINDOW 1000000 /* 1s */
  8054. +#define DEFAULT_SAMPLE_WIDTH 500000 /* 0.5s */
  8055. +#define DEFAULT_LAT_THRESHOLD 10 /* 10us */
  8056. +
  8057. +/* Module metadata */
  8058. +
  8059. +MODULE_LICENSE("GPL");
  8060. +MODULE_AUTHOR("Jon Masters <jcm@redhat.com>");
  8061. +MODULE_DESCRIPTION("A simple hardware latency detector");
  8062. +MODULE_VERSION(VERSION);
  8063. +
  8064. +/* Module parameters */
  8065. +
  8066. +static int debug;
  8067. +static int enabled;
  8068. +static int threshold;
  8069. +
  8070. +module_param(debug, int, 0); /* enable debug */
  8071. +module_param(enabled, int, 0); /* enable detector */
  8072. +module_param(threshold, int, 0); /* latency threshold */
  8073. +
  8074. +/* Buffering and sampling */
  8075. +
  8076. +static struct ring_buffer *ring_buffer; /* sample buffer */
  8077. +static DEFINE_MUTEX(ring_buffer_mutex); /* lock changes */
  8078. +static unsigned long buf_size = BUF_SIZE_DEFAULT;
  8079. +static struct task_struct *kthread; /* sampling thread */
  8080. +
  8081. +/* DebugFS filesystem entries */
  8082. +
  8083. +static struct dentry *debug_dir; /* debugfs directory */
  8084. +static struct dentry *debug_max; /* maximum TSC delta */
  8085. +static struct dentry *debug_count; /* total detect count */
  8086. +static struct dentry *debug_sample_width; /* sample width us */
  8087. +static struct dentry *debug_sample_window; /* sample window us */
  8088. +static struct dentry *debug_sample; /* raw samples us */
  8089. +static struct dentry *debug_threshold; /* threshold us */
  8090. +static struct dentry *debug_enable; /* enable/disable */
  8091. +
  8092. +/* Individual samples and global state */
  8093. +
  8094. +struct sample; /* latency sample */
  8095. +struct data; /* Global state */
  8096. +
  8097. +/* Sampling functions */
  8098. +static int __buffer_add_sample(struct sample *sample);
  8099. +static struct sample *buffer_get_sample(struct sample *sample);
  8100. +
  8101. +/* Threading and state */
  8102. +static int kthread_fn(void *unused);
  8103. +static int start_kthread(void);
  8104. +static int stop_kthread(void);
  8105. +static void __reset_stats(void);
  8106. +static int init_stats(void);
  8107. +
  8108. +/* Debugfs interface */
  8109. +static ssize_t simple_data_read(struct file *filp, char __user *ubuf,
  8110. + size_t cnt, loff_t *ppos, const u64 *entry);
  8111. +static ssize_t simple_data_write(struct file *filp, const char __user *ubuf,
  8112. + size_t cnt, loff_t *ppos, u64 *entry);
  8113. +static int debug_sample_fopen(struct inode *inode, struct file *filp);
  8114. +static ssize_t debug_sample_fread(struct file *filp, char __user *ubuf,
  8115. + size_t cnt, loff_t *ppos);
  8116. +static int debug_sample_release(struct inode *inode, struct file *filp);
  8117. +static int debug_enable_fopen(struct inode *inode, struct file *filp);
  8118. +static ssize_t debug_enable_fread(struct file *filp, char __user *ubuf,
  8119. + size_t cnt, loff_t *ppos);
  8120. +static ssize_t debug_enable_fwrite(struct file *file,
  8121. + const char __user *user_buffer,
  8122. + size_t user_size, loff_t *offset);
  8123. +
  8124. +/* Initialization functions */
  8125. +static int init_debugfs(void);
  8126. +static void free_debugfs(void);
  8127. +static int detector_init(void);
  8128. +static void detector_exit(void);
  8129. +
  8130. +/* Individual latency samples are stored here when detected and packed into
  8131. + * the ring_buffer circular buffer, where they are overwritten when
  8132. + * more than buf_size/sizeof(sample) samples are received. */
  8133. +struct sample {
  8134. + u64 seqnum; /* unique sequence */
  8135. + u64 duration; /* ktime delta */
  8136. + u64 outer_duration; /* ktime delta (outer loop) */
  8137. + struct timespec timestamp; /* wall time */
  8138. + unsigned long lost;
  8139. +};
  8140. +
  8141. +/* keep the global state somewhere. */
  8142. +static struct data {
  8143. +
  8144. + struct mutex lock; /* protect changes */
  8145. +
  8146. + u64 count; /* total since reset */
  8147. + u64 max_sample; /* max hardware latency */
  8148. + u64 threshold; /* sample threshold level */
  8149. +
  8150. + u64 sample_window; /* total sampling window (on+off) */
  8151. + u64 sample_width; /* active sampling portion of window */
  8152. +
  8153. + atomic_t sample_open; /* whether the sample file is open */
  8154. +
  8155. + wait_queue_head_t wq; /* waitqeue for new sample values */
  8156. +
  8157. +} data;
  8158. +
  8159. +/**
  8160. + * __buffer_add_sample - add a new latency sample recording to the ring buffer
  8161. + * @sample: The new latency sample value
  8162. + *
  8163. + * This receives a new latency sample and records it in a global ring buffer.
  8164. + * No additional locking is used in this case.
  8165. + */
  8166. +static int __buffer_add_sample(struct sample *sample)
  8167. +{
  8168. + return ring_buffer_write(ring_buffer,
  8169. + sizeof(struct sample), sample);
  8170. +}
  8171. +
  8172. +/**
  8173. + * buffer_get_sample - remove a hardware latency sample from the ring buffer
  8174. + * @sample: Pre-allocated storage for the sample
  8175. + *
  8176. + * This retrieves a hardware latency sample from the global circular buffer
  8177. + */
  8178. +static struct sample *buffer_get_sample(struct sample *sample)
  8179. +{
  8180. + struct ring_buffer_event *e = NULL;
  8181. + struct sample *s = NULL;
  8182. + unsigned int cpu = 0;
  8183. +
  8184. + if (!sample)
  8185. + return NULL;
  8186. +
  8187. + mutex_lock(&ring_buffer_mutex);
  8188. + for_each_online_cpu(cpu) {
  8189. + e = ring_buffer_consume(ring_buffer, cpu, NULL, &sample->lost);
  8190. + if (e)
  8191. + break;
  8192. + }
  8193. +
  8194. + if (e) {
  8195. + s = ring_buffer_event_data(e);
  8196. + memcpy(sample, s, sizeof(struct sample));
  8197. + } else
  8198. + sample = NULL;
  8199. + mutex_unlock(&ring_buffer_mutex);
  8200. +
  8201. + return sample;
  8202. +}
  8203. +
  8204. +#ifndef CONFIG_TRACING
  8205. +#define time_type ktime_t
  8206. +#define time_get() ktime_get()
  8207. +#define time_to_us(x) ktime_to_us(x)
  8208. +#define time_sub(a, b) ktime_sub(a, b)
  8209. +#define init_time(a, b) (a).tv64 = b
  8210. +#define time_u64(a) ((a).tv64)
  8211. +#else
  8212. +#define time_type u64
  8213. +#define time_get() trace_clock_local()
  8214. +#define time_to_us(x) div_u64(x, 1000)
  8215. +#define time_sub(a, b) ((a) - (b))
  8216. +#define init_time(a, b) (a = b)
  8217. +#define time_u64(a) a
  8218. +#endif
  8219. +/**
  8220. + * get_sample - sample the CPU TSC and look for likely hardware latencies
  8221. + *
  8222. + * Used to repeatedly capture the CPU TSC (or similar), looking for potential
  8223. + * hardware-induced latency. Called with interrupts disabled and with
  8224. + * data.lock held.
  8225. + */
  8226. +static int get_sample(void)
  8227. +{
  8228. + time_type start, t1, t2, last_t2;
  8229. + s64 diff, total = 0;
  8230. + u64 sample = 0;
  8231. + u64 outer_sample = 0;
  8232. + int ret = -1;
  8233. +
  8234. + init_time(last_t2, 0);
  8235. + start = time_get(); /* start timestamp */
  8236. +
  8237. + do {
  8238. +
  8239. + t1 = time_get(); /* we'll look for a discontinuity */
  8240. + t2 = time_get();
  8241. +
  8242. + if (time_u64(last_t2)) {
  8243. + /* Check the delta from outer loop (t2 to next t1) */
  8244. + diff = time_to_us(time_sub(t1, last_t2));
  8245. + /* This shouldn't happen */
  8246. + if (diff < 0) {
  8247. + pr_err(BANNER "time running backwards\n");
  8248. + goto out;
  8249. + }
  8250. + if (diff > outer_sample)
  8251. + outer_sample = diff;
  8252. + }
  8253. + last_t2 = t2;
  8254. +
  8255. + total = time_to_us(time_sub(t2, start)); /* sample width */
  8256. +
  8257. + /* This checks the inner loop (t1 to t2) */
  8258. + diff = time_to_us(time_sub(t2, t1)); /* current diff */
  8259. +
  8260. + /* This shouldn't happen */
  8261. + if (diff < 0) {
  8262. + pr_err(BANNER "time running backwards\n");
  8263. + goto out;
  8264. + }
  8265. +
  8266. + if (diff > sample)
  8267. + sample = diff; /* only want highest value */
  8268. +
  8269. + } while (total <= data.sample_width);
  8270. +
  8271. + ret = 0;
  8272. +
  8273. + /* If we exceed the threshold value, we have found a hardware latency */
  8274. + if (sample > data.threshold || outer_sample > data.threshold) {
  8275. + struct sample s;
  8276. +
  8277. + ret = 1;
  8278. +
  8279. + data.count++;
  8280. + s.seqnum = data.count;
  8281. + s.duration = sample;
  8282. + s.outer_duration = outer_sample;
  8283. + s.timestamp = CURRENT_TIME;
  8284. + __buffer_add_sample(&s);
  8285. +
  8286. + /* Keep a running maximum ever recorded hardware latency */
  8287. + if (sample > data.max_sample)
  8288. + data.max_sample = sample;
  8289. + }
  8290. +
  8291. +out:
  8292. + return ret;
  8293. +}
  8294. +
  8295. +/*
  8296. + * kthread_fn - The CPU time sampling/hardware latency detection kernel thread
  8297. + * @unused: A required part of the kthread API.
  8298. + *
  8299. + * Used to periodically sample the CPU TSC via a call to get_sample. We
  8300. + * disable interrupts, which does (intentionally) introduce latency since we
  8301. + * need to ensure nothing else might be running (and thus pre-empting).
  8302. + * Obviously this should never be used in production environments.
  8303. + *
  8304. + * Currently this runs on which ever CPU it was scheduled on, but most
  8305. + * real-worald hardware latency situations occur across several CPUs,
  8306. + * but we might later generalize this if we find there are any actualy
  8307. + * systems with alternate SMI delivery or other hardware latencies.
  8308. + */
  8309. +static int kthread_fn(void *unused)
  8310. +{
  8311. + int ret;
  8312. + u64 interval;
  8313. +
  8314. + while (!kthread_should_stop()) {
  8315. +
  8316. + mutex_lock(&data.lock);
  8317. +
  8318. + local_irq_disable();
  8319. + ret = get_sample();
  8320. + local_irq_enable();
  8321. +
  8322. + if (ret > 0)
  8323. + wake_up(&data.wq); /* wake up reader(s) */
  8324. +
  8325. + interval = data.sample_window - data.sample_width;
  8326. + do_div(interval, USEC_PER_MSEC); /* modifies interval value */
  8327. +
  8328. + mutex_unlock(&data.lock);
  8329. +
  8330. + if (msleep_interruptible(interval))
  8331. + break;
  8332. + }
  8333. +
  8334. + return 0;
  8335. +}
  8336. +
  8337. +/**
  8338. + * start_kthread - Kick off the hardware latency sampling/detector kthread
  8339. + *
  8340. + * This starts a kernel thread that will sit and sample the CPU timestamp
  8341. + * counter (TSC or similar) and look for potential hardware latencies.
  8342. + */
  8343. +static int start_kthread(void)
  8344. +{
  8345. + kthread = kthread_run(kthread_fn, NULL,
  8346. + DRVNAME);
  8347. + if (IS_ERR(kthread)) {
  8348. + pr_err(BANNER "could not start sampling thread\n");
  8349. + enabled = 0;
  8350. + return -ENOMEM;
  8351. + }
  8352. +
  8353. + return 0;
  8354. +}
  8355. +
  8356. +/**
  8357. + * stop_kthread - Inform the hardware latency samping/detector kthread to stop
  8358. + *
  8359. + * This kicks the running hardware latency sampling/detector kernel thread and
  8360. + * tells it to stop sampling now. Use this on unload and at system shutdown.
  8361. + */
  8362. +static int stop_kthread(void)
  8363. +{
  8364. + int ret;
  8365. +
  8366. + ret = kthread_stop(kthread);
  8367. +
  8368. + return ret;
  8369. +}
  8370. +
  8371. +/**
  8372. + * __reset_stats - Reset statistics for the hardware latency detector
  8373. + *
  8374. + * We use data to store various statistics and global state. We call this
  8375. + * function in order to reset those when "enable" is toggled on or off, and
  8376. + * also at initialization. Should be called with data.lock held.
  8377. + */
  8378. +static void __reset_stats(void)
  8379. +{
  8380. + data.count = 0;
  8381. + data.max_sample = 0;
  8382. + ring_buffer_reset(ring_buffer); /* flush out old sample entries */
  8383. +}
  8384. +
  8385. +/**
  8386. + * init_stats - Setup global state statistics for the hardware latency detector
  8387. + *
  8388. + * We use data to store various statistics and global state. We also use
  8389. + * a global ring buffer (ring_buffer) to keep raw samples of detected hardware
  8390. + * induced system latencies. This function initializes these structures and
  8391. + * allocates the global ring buffer also.
  8392. + */
  8393. +static int init_stats(void)
  8394. +{
  8395. + int ret = -ENOMEM;
  8396. +
  8397. + mutex_init(&data.lock);
  8398. + init_waitqueue_head(&data.wq);
  8399. + atomic_set(&data.sample_open, 0);
  8400. +
  8401. + ring_buffer = ring_buffer_alloc(buf_size, BUF_FLAGS);
  8402. +
  8403. + if (WARN(!ring_buffer, KERN_ERR BANNER
  8404. + "failed to allocate ring buffer!\n"))
  8405. + goto out;
  8406. +
  8407. + __reset_stats();
  8408. + data.threshold = threshold ?: DEFAULT_LAT_THRESHOLD; /* threshold us */
  8409. + data.sample_window = DEFAULT_SAMPLE_WINDOW; /* window us */
  8410. + data.sample_width = DEFAULT_SAMPLE_WIDTH; /* width us */
  8411. +
  8412. + ret = 0;
  8413. +
  8414. +out:
  8415. + return ret;
  8416. +
  8417. +}
  8418. +
  8419. +/*
  8420. + * simple_data_read - Wrapper read function for global state debugfs entries
  8421. + * @filp: The active open file structure for the debugfs "file"
  8422. + * @ubuf: The userspace provided buffer to read value into
  8423. + * @cnt: The maximum number of bytes to read
  8424. + * @ppos: The current "file" position
  8425. + * @entry: The entry to read from
  8426. + *
  8427. + * This function provides a generic read implementation for the global state
  8428. + * "data" structure debugfs filesystem entries. It would be nice to use
  8429. + * simple_attr_read directly, but we need to make sure that the data.lock
  8430. + * is held during the actual read.
  8431. + */
  8432. +static ssize_t simple_data_read(struct file *filp, char __user *ubuf,
  8433. + size_t cnt, loff_t *ppos, const u64 *entry)
  8434. +{
  8435. + char buf[U64STR_SIZE];
  8436. + u64 val = 0;
  8437. + int len = 0;
  8438. +
  8439. + memset(buf, 0, sizeof(buf));
  8440. +
  8441. + if (!entry)
  8442. + return -EFAULT;
  8443. +
  8444. + mutex_lock(&data.lock);
  8445. + val = *entry;
  8446. + mutex_unlock(&data.lock);
  8447. +
  8448. + len = snprintf(buf, sizeof(buf), "%llu\n", (unsigned long long)val);
  8449. +
  8450. + return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
  8451. +
  8452. +}
  8453. +
  8454. +/*
  8455. + * simple_data_write - Wrapper write function for global state debugfs entries
  8456. + * @filp: The active open file structure for the debugfs "file"
  8457. + * @ubuf: The userspace provided buffer to write value from
  8458. + * @cnt: The maximum number of bytes to write
  8459. + * @ppos: The current "file" position
  8460. + * @entry: The entry to write to
  8461. + *
  8462. + * This function provides a generic write implementation for the global state
  8463. + * "data" structure debugfs filesystem entries. It would be nice to use
  8464. + * simple_attr_write directly, but we need to make sure that the data.lock
  8465. + * is held during the actual write.
  8466. + */
  8467. +static ssize_t simple_data_write(struct file *filp, const char __user *ubuf,
  8468. + size_t cnt, loff_t *ppos, u64 *entry)
  8469. +{
  8470. + char buf[U64STR_SIZE];
  8471. + int csize = min(cnt, sizeof(buf));
  8472. + u64 val = 0;
  8473. + int err = 0;
  8474. +
  8475. + memset(buf, '\0', sizeof(buf));
  8476. + if (copy_from_user(buf, ubuf, csize))
  8477. + return -EFAULT;
  8478. +
  8479. + buf[U64STR_SIZE-1] = '\0'; /* just in case */
  8480. + err = kstrtoull(buf, 10, &val);
  8481. + if (err)
  8482. + return -EINVAL;
  8483. +
  8484. + mutex_lock(&data.lock);
  8485. + *entry = val;
  8486. + mutex_unlock(&data.lock);
  8487. +
  8488. + return csize;
  8489. +}
  8490. +
  8491. +/**
  8492. + * debug_count_fopen - Open function for "count" debugfs entry
  8493. + * @inode: The in-kernel inode representation of the debugfs "file"
  8494. + * @filp: The active open file structure for the debugfs "file"
  8495. + *
  8496. + * This function provides an open implementation for the "count" debugfs
  8497. + * interface to the hardware latency detector.
  8498. + */
  8499. +static int debug_count_fopen(struct inode *inode, struct file *filp)
  8500. +{
  8501. + return 0;
  8502. +}
  8503. +
  8504. +/**
  8505. + * debug_count_fread - Read function for "count" debugfs entry
  8506. + * @filp: The active open file structure for the debugfs "file"
  8507. + * @ubuf: The userspace provided buffer to read value into
  8508. + * @cnt: The maximum number of bytes to read
  8509. + * @ppos: The current "file" position
  8510. + *
  8511. + * This function provides a read implementation for the "count" debugfs
  8512. + * interface to the hardware latency detector. Can be used to read the
  8513. + * number of latency readings exceeding the configured threshold since
  8514. + * the detector was last reset (e.g. by writing a zero into "count").
  8515. + */
  8516. +static ssize_t debug_count_fread(struct file *filp, char __user *ubuf,
  8517. + size_t cnt, loff_t *ppos)
  8518. +{
  8519. + return simple_data_read(filp, ubuf, cnt, ppos, &data.count);
  8520. +}
  8521. +
  8522. +/**
  8523. + * debug_count_fwrite - Write function for "count" debugfs entry
  8524. + * @filp: The active open file structure for the debugfs "file"
  8525. + * @ubuf: The user buffer that contains the value to write
  8526. + * @cnt: The maximum number of bytes to write to "file"
  8527. + * @ppos: The current position in the debugfs "file"
  8528. + *
  8529. + * This function provides a write implementation for the "count" debugfs
  8530. + * interface to the hardware latency detector. Can be used to write a
  8531. + * desired value, especially to zero the total count.
  8532. + */
  8533. +static ssize_t debug_count_fwrite(struct file *filp,
  8534. + const char __user *ubuf,
  8535. + size_t cnt,
  8536. + loff_t *ppos)
  8537. +{
  8538. + return simple_data_write(filp, ubuf, cnt, ppos, &data.count);
  8539. +}
  8540. +
  8541. +/**
  8542. + * debug_enable_fopen - Dummy open function for "enable" debugfs interface
  8543. + * @inode: The in-kernel inode representation of the debugfs "file"
  8544. + * @filp: The active open file structure for the debugfs "file"
  8545. + *
  8546. + * This function provides an open implementation for the "enable" debugfs
  8547. + * interface to the hardware latency detector.
  8548. + */
  8549. +static int debug_enable_fopen(struct inode *inode, struct file *filp)
  8550. +{
  8551. + return 0;
  8552. +}
  8553. +
  8554. +/**
  8555. + * debug_enable_fread - Read function for "enable" debugfs interface
  8556. + * @filp: The active open file structure for the debugfs "file"
  8557. + * @ubuf: The userspace provided buffer to read value into
  8558. + * @cnt: The maximum number of bytes to read
  8559. + * @ppos: The current "file" position
  8560. + *
  8561. + * This function provides a read implementation for the "enable" debugfs
  8562. + * interface to the hardware latency detector. Can be used to determine
  8563. + * whether the detector is currently enabled ("0\n" or "1\n" returned).
  8564. + */
  8565. +static ssize_t debug_enable_fread(struct file *filp, char __user *ubuf,
  8566. + size_t cnt, loff_t *ppos)
  8567. +{
  8568. + char buf[4];
  8569. +
  8570. + if ((cnt < sizeof(buf)) || (*ppos))
  8571. + return 0;
  8572. +
  8573. + buf[0] = enabled ? '1' : '0';
  8574. + buf[1] = '\n';
  8575. + buf[2] = '\0';
  8576. + if (copy_to_user(ubuf, buf, strlen(buf)))
  8577. + return -EFAULT;
  8578. + return *ppos = strlen(buf);
  8579. +}
  8580. +
  8581. +/**
  8582. + * debug_enable_fwrite - Write function for "enable" debugfs interface
  8583. + * @filp: The active open file structure for the debugfs "file"
  8584. + * @ubuf: The user buffer that contains the value to write
  8585. + * @cnt: The maximum number of bytes to write to "file"
  8586. + * @ppos: The current position in the debugfs "file"
  8587. + *
  8588. + * This function provides a write implementation for the "enable" debugfs
  8589. + * interface to the hardware latency detector. Can be used to enable or
  8590. + * disable the detector, which will have the side-effect of possibly
  8591. + * also resetting the global stats and kicking off the measuring
  8592. + * kthread (on an enable) or the converse (upon a disable).
  8593. + */
  8594. +static ssize_t debug_enable_fwrite(struct file *filp,
  8595. + const char __user *ubuf,
  8596. + size_t cnt,
  8597. + loff_t *ppos)
  8598. +{
  8599. + char buf[4];
  8600. + int csize = min(cnt, sizeof(buf));
  8601. + long val = 0;
  8602. + int err = 0;
  8603. +
  8604. + memset(buf, '\0', sizeof(buf));
  8605. + if (copy_from_user(buf, ubuf, csize))
  8606. + return -EFAULT;
  8607. +
  8608. + buf[sizeof(buf)-1] = '\0'; /* just in case */
  8609. + err = kstrtoul(buf, 10, &val);
  8610. + if (err)
  8611. + return -EINVAL;
  8612. +
  8613. + if (val) {
  8614. + if (enabled)
  8615. + goto unlock;
  8616. + enabled = 1;
  8617. + __reset_stats();
  8618. + if (start_kthread())
  8619. + return -EFAULT;
  8620. + } else {
  8621. + if (!enabled)
  8622. + goto unlock;
  8623. + enabled = 0;
  8624. + err = stop_kthread();
  8625. + if (err) {
  8626. + pr_err(BANNER "cannot stop kthread\n");
  8627. + return -EFAULT;
  8628. + }
  8629. + wake_up(&data.wq); /* reader(s) should return */
  8630. + }
  8631. +unlock:
  8632. + return csize;
  8633. +}
  8634. +
  8635. +/**
  8636. + * debug_max_fopen - Open function for "max" debugfs entry
  8637. + * @inode: The in-kernel inode representation of the debugfs "file"
  8638. + * @filp: The active open file structure for the debugfs "file"
  8639. + *
  8640. + * This function provides an open implementation for the "max" debugfs
  8641. + * interface to the hardware latency detector.
  8642. + */
  8643. +static int debug_max_fopen(struct inode *inode, struct file *filp)
  8644. +{
  8645. + return 0;
  8646. +}
  8647. +
  8648. +/**
  8649. + * debug_max_fread - Read function for "max" debugfs entry
  8650. + * @filp: The active open file structure for the debugfs "file"
  8651. + * @ubuf: The userspace provided buffer to read value into
  8652. + * @cnt: The maximum number of bytes to read
  8653. + * @ppos: The current "file" position
  8654. + *
  8655. + * This function provides a read implementation for the "max" debugfs
  8656. + * interface to the hardware latency detector. Can be used to determine
  8657. + * the maximum latency value observed since it was last reset.
  8658. + */
  8659. +static ssize_t debug_max_fread(struct file *filp, char __user *ubuf,
  8660. + size_t cnt, loff_t *ppos)
  8661. +{
  8662. + return simple_data_read(filp, ubuf, cnt, ppos, &data.max_sample);
  8663. +}
  8664. +
  8665. +/**
  8666. + * debug_max_fwrite - Write function for "max" debugfs entry
  8667. + * @filp: The active open file structure for the debugfs "file"
  8668. + * @ubuf: The user buffer that contains the value to write
  8669. + * @cnt: The maximum number of bytes to write to "file"
  8670. + * @ppos: The current position in the debugfs "file"
  8671. + *
  8672. + * This function provides a write implementation for the "max" debugfs
  8673. + * interface to the hardware latency detector. Can be used to reset the
  8674. + * maximum or set it to some other desired value - if, then, subsequent
  8675. + * measurements exceed this value, the maximum will be updated.
  8676. + */
  8677. +static ssize_t debug_max_fwrite(struct file *filp,
  8678. + const char __user *ubuf,
  8679. + size_t cnt,
  8680. + loff_t *ppos)
  8681. +{
  8682. + return simple_data_write(filp, ubuf, cnt, ppos, &data.max_sample);
  8683. +}
  8684. +
  8685. +
  8686. +/**
  8687. + * debug_sample_fopen - An open function for "sample" debugfs interface
  8688. + * @inode: The in-kernel inode representation of this debugfs "file"
  8689. + * @filp: The active open file structure for the debugfs "file"
  8690. + *
  8691. + * This function handles opening the "sample" file within the hardware
  8692. + * latency detector debugfs directory interface. This file is used to read
  8693. + * raw samples from the global ring_buffer and allows the user to see a
  8694. + * running latency history. Can be opened blocking or non-blocking,
  8695. + * affecting whether it behaves as a buffer read pipe, or does not.
  8696. + * Implements simple locking to prevent multiple simultaneous use.
  8697. + */
  8698. +static int debug_sample_fopen(struct inode *inode, struct file *filp)
  8699. +{
  8700. + if (!atomic_add_unless(&data.sample_open, 1, 1))
  8701. + return -EBUSY;
  8702. + else
  8703. + return 0;
  8704. +}
  8705. +
  8706. +/**
  8707. + * debug_sample_fread - A read function for "sample" debugfs interface
  8708. + * @filp: The active open file structure for the debugfs "file"
  8709. + * @ubuf: The user buffer that will contain the samples read
  8710. + * @cnt: The maximum bytes to read from the debugfs "file"
  8711. + * @ppos: The current position in the debugfs "file"
  8712. + *
  8713. + * This function handles reading from the "sample" file within the hardware
  8714. + * latency detector debugfs directory interface. This file is used to read
  8715. + * raw samples from the global ring_buffer and allows the user to see a
  8716. + * running latency history. By default this will block pending a new
  8717. + * value written into the sample buffer, unless there are already a
  8718. + * number of value(s) waiting in the buffer, or the sample file was
  8719. + * previously opened in a non-blocking mode of operation.
  8720. + */
  8721. +static ssize_t debug_sample_fread(struct file *filp, char __user *ubuf,
  8722. + size_t cnt, loff_t *ppos)
  8723. +{
  8724. + int len = 0;
  8725. + char buf[64];
  8726. + struct sample *sample = NULL;
  8727. +
  8728. + if (!enabled)
  8729. + return 0;
  8730. +
  8731. + sample = kzalloc(sizeof(struct sample), GFP_KERNEL);
  8732. + if (!sample)
  8733. + return -ENOMEM;
  8734. +
  8735. + while (!buffer_get_sample(sample)) {
  8736. +
  8737. + DEFINE_WAIT(wait);
  8738. +
  8739. + if (filp->f_flags & O_NONBLOCK) {
  8740. + len = -EAGAIN;
  8741. + goto out;
  8742. + }
  8743. +
  8744. + prepare_to_wait(&data.wq, &wait, TASK_INTERRUPTIBLE);
  8745. + schedule();
  8746. + finish_wait(&data.wq, &wait);
  8747. +
  8748. + if (signal_pending(current)) {
  8749. + len = -EINTR;
  8750. + goto out;
  8751. + }
  8752. +
  8753. + if (!enabled) { /* enable was toggled */
  8754. + len = 0;
  8755. + goto out;
  8756. + }
  8757. + }
  8758. +
  8759. + len = snprintf(buf, sizeof(buf), "%010lu.%010lu\t%llu\t%llu\n",
  8760. + sample->timestamp.tv_sec,
  8761. + sample->timestamp.tv_nsec,
  8762. + sample->duration,
  8763. + sample->outer_duration);
  8764. +
  8765. +
  8766. + /* handling partial reads is more trouble than it's worth */
  8767. + if (len > cnt)
  8768. + goto out;
  8769. +
  8770. + if (copy_to_user(ubuf, buf, len))
  8771. + len = -EFAULT;
  8772. +
  8773. +out:
  8774. + kfree(sample);
  8775. + return len;
  8776. +}
  8777. +
  8778. +/**
  8779. + * debug_sample_release - Release function for "sample" debugfs interface
  8780. + * @inode: The in-kernel inode represenation of the debugfs "file"
  8781. + * @filp: The active open file structure for the debugfs "file"
  8782. + *
  8783. + * This function completes the close of the debugfs interface "sample" file.
  8784. + * Frees the sample_open "lock" so that other users may open the interface.
  8785. + */
  8786. +static int debug_sample_release(struct inode *inode, struct file *filp)
  8787. +{
  8788. + atomic_dec(&data.sample_open);
  8789. +
  8790. + return 0;
  8791. +}
  8792. +
  8793. +/**
  8794. + * debug_threshold_fopen - Open function for "threshold" debugfs entry
  8795. + * @inode: The in-kernel inode representation of the debugfs "file"
  8796. + * @filp: The active open file structure for the debugfs "file"
  8797. + *
  8798. + * This function provides an open implementation for the "threshold" debugfs
  8799. + * interface to the hardware latency detector.
  8800. + */
  8801. +static int debug_threshold_fopen(struct inode *inode, struct file *filp)
  8802. +{
  8803. + return 0;
  8804. +}
  8805. +
  8806. +/**
  8807. + * debug_threshold_fread - Read function for "threshold" debugfs entry
  8808. + * @filp: The active open file structure for the debugfs "file"
  8809. + * @ubuf: The userspace provided buffer to read value into
  8810. + * @cnt: The maximum number of bytes to read
  8811. + * @ppos: The current "file" position
  8812. + *
  8813. + * This function provides a read implementation for the "threshold" debugfs
  8814. + * interface to the hardware latency detector. It can be used to determine
  8815. + * the current threshold level at which a latency will be recorded in the
  8816. + * global ring buffer, typically on the order of 10us.
  8817. + */
  8818. +static ssize_t debug_threshold_fread(struct file *filp, char __user *ubuf,
  8819. + size_t cnt, loff_t *ppos)
  8820. +{
  8821. + return simple_data_read(filp, ubuf, cnt, ppos, &data.threshold);
  8822. +}
  8823. +
  8824. +/**
  8825. + * debug_threshold_fwrite - Write function for "threshold" debugfs entry
  8826. + * @filp: The active open file structure for the debugfs "file"
  8827. + * @ubuf: The user buffer that contains the value to write
  8828. + * @cnt: The maximum number of bytes to write to "file"
  8829. + * @ppos: The current position in the debugfs "file"
  8830. + *
  8831. + * This function provides a write implementation for the "threshold" debugfs
  8832. + * interface to the hardware latency detector. It can be used to configure
  8833. + * the threshold level at which any subsequently detected latencies will
  8834. + * be recorded into the global ring buffer.
  8835. + */
  8836. +static ssize_t debug_threshold_fwrite(struct file *filp,
  8837. + const char __user *ubuf,
  8838. + size_t cnt,
  8839. + loff_t *ppos)
  8840. +{
  8841. + int ret;
  8842. +
  8843. + ret = simple_data_write(filp, ubuf, cnt, ppos, &data.threshold);
  8844. +
  8845. + if (enabled)
  8846. + wake_up_process(kthread);
  8847. +
  8848. + return ret;
  8849. +}
  8850. +
  8851. +/**
  8852. + * debug_width_fopen - Open function for "width" debugfs entry
  8853. + * @inode: The in-kernel inode representation of the debugfs "file"
  8854. + * @filp: The active open file structure for the debugfs "file"
  8855. + *
  8856. + * This function provides an open implementation for the "width" debugfs
  8857. + * interface to the hardware latency detector.
  8858. + */
  8859. +static int debug_width_fopen(struct inode *inode, struct file *filp)
  8860. +{
  8861. + return 0;
  8862. +}
  8863. +
  8864. +/**
  8865. + * debug_width_fread - Read function for "width" debugfs entry
  8866. + * @filp: The active open file structure for the debugfs "file"
  8867. + * @ubuf: The userspace provided buffer to read value into
  8868. + * @cnt: The maximum number of bytes to read
  8869. + * @ppos: The current "file" position
  8870. + *
  8871. + * This function provides a read implementation for the "width" debugfs
  8872. + * interface to the hardware latency detector. It can be used to determine
  8873. + * for how many us of the total window us we will actively sample for any
  8874. + * hardware-induced latecy periods. Obviously, it is not possible to
  8875. + * sample constantly and have the system respond to a sample reader, or,
  8876. + * worse, without having the system appear to have gone out to lunch.
  8877. + */
  8878. +static ssize_t debug_width_fread(struct file *filp, char __user *ubuf,
  8879. + size_t cnt, loff_t *ppos)
  8880. +{
  8881. + return simple_data_read(filp, ubuf, cnt, ppos, &data.sample_width);
  8882. +}
  8883. +
  8884. +/**
  8885. + * debug_width_fwrite - Write function for "width" debugfs entry
  8886. + * @filp: The active open file structure for the debugfs "file"
  8887. + * @ubuf: The user buffer that contains the value to write
  8888. + * @cnt: The maximum number of bytes to write to "file"
  8889. + * @ppos: The current position in the debugfs "file"
  8890. + *
  8891. + * This function provides a write implementation for the "width" debugfs
  8892. + * interface to the hardware latency detector. It can be used to configure
  8893. + * for how many us of the total window us we will actively sample for any
  8894. + * hardware-induced latency periods. Obviously, it is not possible to
  8895. + * sample constantly and have the system respond to a sample reader, or,
  8896. + * worse, without having the system appear to have gone out to lunch. It
  8897. + * is enforced that width is less that the total window size.
  8898. + */
  8899. +static ssize_t debug_width_fwrite(struct file *filp,
  8900. + const char __user *ubuf,
  8901. + size_t cnt,
  8902. + loff_t *ppos)
  8903. +{
  8904. + char buf[U64STR_SIZE];
  8905. + int csize = min(cnt, sizeof(buf));
  8906. + u64 val = 0;
  8907. + int err = 0;
  8908. +
  8909. + memset(buf, '\0', sizeof(buf));
  8910. + if (copy_from_user(buf, ubuf, csize))
  8911. + return -EFAULT;
  8912. +
  8913. + buf[U64STR_SIZE-1] = '\0'; /* just in case */
  8914. + err = kstrtoull(buf, 10, &val);
  8915. + if (err)
  8916. + return -EINVAL;
  8917. +
  8918. + mutex_lock(&data.lock);
  8919. + if (val < data.sample_window)
  8920. + data.sample_width = val;
  8921. + else {
  8922. + mutex_unlock(&data.lock);
  8923. + return -EINVAL;
  8924. + }
  8925. + mutex_unlock(&data.lock);
  8926. +
  8927. + if (enabled)
  8928. + wake_up_process(kthread);
  8929. +
  8930. + return csize;
  8931. +}
  8932. +
  8933. +/**
  8934. + * debug_window_fopen - Open function for "window" debugfs entry
  8935. + * @inode: The in-kernel inode representation of the debugfs "file"
  8936. + * @filp: The active open file structure for the debugfs "file"
  8937. + *
  8938. + * This function provides an open implementation for the "window" debugfs
  8939. + * interface to the hardware latency detector. The window is the total time
  8940. + * in us that will be considered one sample period. Conceptually, windows
  8941. + * occur back-to-back and contain a sample width period during which
  8942. + * actual sampling occurs.
  8943. + */
  8944. +static int debug_window_fopen(struct inode *inode, struct file *filp)
  8945. +{
  8946. + return 0;
  8947. +}
  8948. +
  8949. +/**
  8950. + * debug_window_fread - Read function for "window" debugfs entry
  8951. + * @filp: The active open file structure for the debugfs "file"
  8952. + * @ubuf: The userspace provided buffer to read value into
  8953. + * @cnt: The maximum number of bytes to read
  8954. + * @ppos: The current "file" position
  8955. + *
  8956. + * This function provides a read implementation for the "window" debugfs
  8957. + * interface to the hardware latency detector. The window is the total time
  8958. + * in us that will be considered one sample period. Conceptually, windows
  8959. + * occur back-to-back and contain a sample width period during which
  8960. + * actual sampling occurs. Can be used to read the total window size.
  8961. + */
  8962. +static ssize_t debug_window_fread(struct file *filp, char __user *ubuf,
  8963. + size_t cnt, loff_t *ppos)
  8964. +{
  8965. + return simple_data_read(filp, ubuf, cnt, ppos, &data.sample_window);
  8966. +}
  8967. +
  8968. +/**
  8969. + * debug_window_fwrite - Write function for "window" debugfs entry
  8970. + * @filp: The active open file structure for the debugfs "file"
  8971. + * @ubuf: The user buffer that contains the value to write
  8972. + * @cnt: The maximum number of bytes to write to "file"
  8973. + * @ppos: The current position in the debugfs "file"
  8974. + *
  8975. + * This function provides a write implementation for the "window" debufds
  8976. + * interface to the hardware latency detetector. The window is the total time
  8977. + * in us that will be considered one sample period. Conceptually, windows
  8978. + * occur back-to-back and contain a sample width period during which
  8979. + * actual sampling occurs. Can be used to write a new total window size. It
  8980. + * is enfoced that any value written must be greater than the sample width
  8981. + * size, or an error results.
  8982. + */
  8983. +static ssize_t debug_window_fwrite(struct file *filp,
  8984. + const char __user *ubuf,
  8985. + size_t cnt,
  8986. + loff_t *ppos)
  8987. +{
  8988. + char buf[U64STR_SIZE];
  8989. + int csize = min(cnt, sizeof(buf));
  8990. + u64 val = 0;
  8991. + int err = 0;
  8992. +
  8993. + memset(buf, '\0', sizeof(buf));
  8994. + if (copy_from_user(buf, ubuf, csize))
  8995. + return -EFAULT;
  8996. +
  8997. + buf[U64STR_SIZE-1] = '\0'; /* just in case */
  8998. + err = kstrtoull(buf, 10, &val);
  8999. + if (err)
  9000. + return -EINVAL;
  9001. +
  9002. + mutex_lock(&data.lock);
  9003. + if (data.sample_width < val)
  9004. + data.sample_window = val;
  9005. + else {
  9006. + mutex_unlock(&data.lock);
  9007. + return -EINVAL;
  9008. + }
  9009. + mutex_unlock(&data.lock);
  9010. +
  9011. + return csize;
  9012. +}
  9013. +
  9014. +/*
  9015. + * Function pointers for the "count" debugfs file operations
  9016. + */
  9017. +static const struct file_operations count_fops = {
  9018. + .open = debug_count_fopen,
  9019. + .read = debug_count_fread,
  9020. + .write = debug_count_fwrite,
  9021. + .owner = THIS_MODULE,
  9022. +};
  9023. +
  9024. +/*
  9025. + * Function pointers for the "enable" debugfs file operations
  9026. + */
  9027. +static const struct file_operations enable_fops = {
  9028. + .open = debug_enable_fopen,
  9029. + .read = debug_enable_fread,
  9030. + .write = debug_enable_fwrite,
  9031. + .owner = THIS_MODULE,
  9032. +};
  9033. +
  9034. +/*
  9035. + * Function pointers for the "max" debugfs file operations
  9036. + */
  9037. +static const struct file_operations max_fops = {
  9038. + .open = debug_max_fopen,
  9039. + .read = debug_max_fread,
  9040. + .write = debug_max_fwrite,
  9041. + .owner = THIS_MODULE,
  9042. +};
  9043. +
  9044. +/*
  9045. + * Function pointers for the "sample" debugfs file operations
  9046. + */
  9047. +static const struct file_operations sample_fops = {
  9048. + .open = debug_sample_fopen,
  9049. + .read = debug_sample_fread,
  9050. + .release = debug_sample_release,
  9051. + .owner = THIS_MODULE,
  9052. +};
  9053. +
  9054. +/*
  9055. + * Function pointers for the "threshold" debugfs file operations
  9056. + */
  9057. +static const struct file_operations threshold_fops = {
  9058. + .open = debug_threshold_fopen,
  9059. + .read = debug_threshold_fread,
  9060. + .write = debug_threshold_fwrite,
  9061. + .owner = THIS_MODULE,
  9062. +};
  9063. +
  9064. +/*
  9065. + * Function pointers for the "width" debugfs file operations
  9066. + */
  9067. +static const struct file_operations width_fops = {
  9068. + .open = debug_width_fopen,
  9069. + .read = debug_width_fread,
  9070. + .write = debug_width_fwrite,
  9071. + .owner = THIS_MODULE,
  9072. +};
  9073. +
  9074. +/*
  9075. + * Function pointers for the "window" debugfs file operations
  9076. + */
  9077. +static const struct file_operations window_fops = {
  9078. + .open = debug_window_fopen,
  9079. + .read = debug_window_fread,
  9080. + .write = debug_window_fwrite,
  9081. + .owner = THIS_MODULE,
  9082. +};
  9083. +
  9084. +/**
  9085. + * init_debugfs - A function to initialize the debugfs interface files
  9086. + *
  9087. + * This function creates entries in debugfs for "hwlat_detector", including
  9088. + * files to read values from the detector, current samples, and the
  9089. + * maximum sample that has been captured since the hardware latency
  9090. + * dectector was started.
  9091. + */
  9092. +static int init_debugfs(void)
  9093. +{
  9094. + int ret = -ENOMEM;
  9095. +
  9096. + debug_dir = debugfs_create_dir(DRVNAME, NULL);
  9097. + if (!debug_dir)
  9098. + goto err_debug_dir;
  9099. +
  9100. + debug_sample = debugfs_create_file("sample", 0444,
  9101. + debug_dir, NULL,
  9102. + &sample_fops);
  9103. + if (!debug_sample)
  9104. + goto err_sample;
  9105. +
  9106. + debug_count = debugfs_create_file("count", 0444,
  9107. + debug_dir, NULL,
  9108. + &count_fops);
  9109. + if (!debug_count)
  9110. + goto err_count;
  9111. +
  9112. + debug_max = debugfs_create_file("max", 0444,
  9113. + debug_dir, NULL,
  9114. + &max_fops);
  9115. + if (!debug_max)
  9116. + goto err_max;
  9117. +
  9118. + debug_sample_window = debugfs_create_file("window", 0644,
  9119. + debug_dir, NULL,
  9120. + &window_fops);
  9121. + if (!debug_sample_window)
  9122. + goto err_window;
  9123. +
  9124. + debug_sample_width = debugfs_create_file("width", 0644,
  9125. + debug_dir, NULL,
  9126. + &width_fops);
  9127. + if (!debug_sample_width)
  9128. + goto err_width;
  9129. +
  9130. + debug_threshold = debugfs_create_file("threshold", 0644,
  9131. + debug_dir, NULL,
  9132. + &threshold_fops);
  9133. + if (!debug_threshold)
  9134. + goto err_threshold;
  9135. +
  9136. + debug_enable = debugfs_create_file("enable", 0644,
  9137. + debug_dir, &enabled,
  9138. + &enable_fops);
  9139. + if (!debug_enable)
  9140. + goto err_enable;
  9141. +
  9142. + else {
  9143. + ret = 0;
  9144. + goto out;
  9145. + }
  9146. +
  9147. +err_enable:
  9148. + debugfs_remove(debug_threshold);
  9149. +err_threshold:
  9150. + debugfs_remove(debug_sample_width);
  9151. +err_width:
  9152. + debugfs_remove(debug_sample_window);
  9153. +err_window:
  9154. + debugfs_remove(debug_max);
  9155. +err_max:
  9156. + debugfs_remove(debug_count);
  9157. +err_count:
  9158. + debugfs_remove(debug_sample);
  9159. +err_sample:
  9160. + debugfs_remove(debug_dir);
  9161. +err_debug_dir:
  9162. +out:
  9163. + return ret;
  9164. +}
  9165. +
  9166. +/**
  9167. + * free_debugfs - A function to cleanup the debugfs file interface
  9168. + */
  9169. +static void free_debugfs(void)
  9170. +{
  9171. + /* could also use a debugfs_remove_recursive */
  9172. + debugfs_remove(debug_enable);
  9173. + debugfs_remove(debug_threshold);
  9174. + debugfs_remove(debug_sample_width);
  9175. + debugfs_remove(debug_sample_window);
  9176. + debugfs_remove(debug_max);
  9177. + debugfs_remove(debug_count);
  9178. + debugfs_remove(debug_sample);
  9179. + debugfs_remove(debug_dir);
  9180. +}
  9181. +
  9182. +/**
  9183. + * detector_init - Standard module initialization code
  9184. + */
  9185. +static int detector_init(void)
  9186. +{
  9187. + int ret = -ENOMEM;
  9188. +
  9189. + pr_info(BANNER "version %s\n", VERSION);
  9190. +
  9191. + ret = init_stats();
  9192. + if (ret)
  9193. + goto out;
  9194. +
  9195. + ret = init_debugfs();
  9196. + if (ret)
  9197. + goto err_stats;
  9198. +
  9199. + if (enabled)
  9200. + ret = start_kthread();
  9201. +
  9202. + goto out;
  9203. +
  9204. +err_stats:
  9205. + ring_buffer_free(ring_buffer);
  9206. +out:
  9207. + return ret;
  9208. +
  9209. +}
  9210. +
  9211. +/**
  9212. + * detector_exit - Standard module cleanup code
  9213. + */
  9214. +static void detector_exit(void)
  9215. +{
  9216. + int err;
  9217. +
  9218. + if (enabled) {
  9219. + enabled = 0;
  9220. + err = stop_kthread();
  9221. + if (err)
  9222. + pr_err(BANNER "cannot stop kthread\n");
  9223. + }
  9224. +
  9225. + free_debugfs();
  9226. + ring_buffer_free(ring_buffer); /* free up the ring buffer */
  9227. +
  9228. +}
  9229. +
  9230. +module_init(detector_init);
  9231. +module_exit(detector_exit);
  9232. diff -Nur linux-4.4.13.orig/drivers/misc/Kconfig linux-4.4.13/drivers/misc/Kconfig
  9233. --- linux-4.4.13.orig/drivers/misc/Kconfig 2016-06-08 03:14:51.000000000 +0200
  9234. +++ linux-4.4.13/drivers/misc/Kconfig 2016-06-22 21:55:08.010523867 +0200
  9235. @@ -54,6 +54,7 @@
  9236. config ATMEL_TCLIB
  9237. bool "Atmel AT32/AT91 Timer/Counter Library"
  9238. depends on (AVR32 || ARCH_AT91)
  9239. + default y if PREEMPT_RT_FULL
  9240. help
  9241. Select this if you want a library to allocate the Timer/Counter
  9242. blocks found on many Atmel processors. This facilitates using
  9243. @@ -69,8 +70,7 @@
  9244. are combined to make a single 32-bit timer.
  9245. When GENERIC_CLOCKEVENTS is defined, the third timer channel
  9246. - may be used as a clock event device supporting oneshot mode
  9247. - (delays of up to two seconds) based on the 32 KiHz clock.
  9248. + may be used as a clock event device supporting oneshot mode.
  9249. config ATMEL_TCB_CLKSRC_BLOCK
  9250. int
  9251. @@ -84,6 +84,15 @@
  9252. TC can be used for other purposes, such as PWM generation and
  9253. interval timing.
  9254. +config ATMEL_TCB_CLKSRC_USE_SLOW_CLOCK
  9255. + bool "TC Block use 32 KiHz clock"
  9256. + depends on ATMEL_TCB_CLKSRC
  9257. + default y if !PREEMPT_RT_FULL
  9258. + help
  9259. + Select this to use 32 KiHz base clock rate as TC block clock
  9260. + source for clock events.
  9261. +
  9262. +
  9263. config DUMMY_IRQ
  9264. tristate "Dummy IRQ handler"
  9265. default n
  9266. @@ -113,6 +122,35 @@
  9267. for information on the specific driver level and support statement
  9268. for your IBM server.
  9269. +config HWLAT_DETECTOR
  9270. + tristate "Testing module to detect hardware-induced latencies"
  9271. + depends on DEBUG_FS
  9272. + depends on RING_BUFFER
  9273. + default m
  9274. + ---help---
  9275. + A simple hardware latency detector. Use this module to detect
  9276. + large latencies introduced by the behavior of the underlying
  9277. + system firmware external to Linux. We do this using periodic
  9278. + use of stop_machine to grab all available CPUs and measure
  9279. + for unexplainable gaps in the CPU timestamp counter(s). By
  9280. + default, the module is not enabled until the "enable" file
  9281. + within the "hwlat_detector" debugfs directory is toggled.
  9282. +
  9283. + This module is often used to detect SMI (System Management
  9284. + Interrupts) on x86 systems, though is not x86 specific. To
  9285. + this end, we default to using a sample window of 1 second,
  9286. + during which we will sample for 0.5 seconds. If an SMI or
  9287. + similar event occurs during that time, it is recorded
  9288. + into an 8K samples global ring buffer until retreived.
  9289. +
  9290. + WARNING: This software should never be enabled (it can be built
  9291. + but should not be turned on after it is loaded) in a production
  9292. + environment where high latencies are a concern since the
  9293. + sampling mechanism actually introduces latencies for
  9294. + regular tasks while the CPU(s) are being held.
  9295. +
  9296. + If unsure, say N
  9297. +
  9298. config PHANTOM
  9299. tristate "Sensable PHANToM (PCI)"
  9300. depends on PCI
  9301. diff -Nur linux-4.4.13.orig/drivers/misc/Makefile linux-4.4.13/drivers/misc/Makefile
  9302. --- linux-4.4.13.orig/drivers/misc/Makefile 2016-06-08 03:14:51.000000000 +0200
  9303. +++ linux-4.4.13/drivers/misc/Makefile 2016-06-22 21:55:08.010523867 +0200
  9304. @@ -39,6 +39,7 @@
  9305. obj-$(CONFIG_HMC6352) += hmc6352.o
  9306. obj-y += eeprom/
  9307. obj-y += cb710/
  9308. +obj-$(CONFIG_HWLAT_DETECTOR) += hwlat_detector.o
  9309. obj-$(CONFIG_SPEAR13XX_PCIE_GADGET) += spear13xx_pcie_gadget.o
  9310. obj-$(CONFIG_VMWARE_BALLOON) += vmw_balloon.o
  9311. obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o
  9312. diff -Nur linux-4.4.13.orig/drivers/mmc/host/mmci.c linux-4.4.13/drivers/mmc/host/mmci.c
  9313. --- linux-4.4.13.orig/drivers/mmc/host/mmci.c 2016-06-08 03:14:51.000000000 +0200
  9314. +++ linux-4.4.13/drivers/mmc/host/mmci.c 2016-06-22 21:55:08.010523867 +0200
  9315. @@ -1155,15 +1155,12 @@
  9316. struct sg_mapping_iter *sg_miter = &host->sg_miter;
  9317. struct variant_data *variant = host->variant;
  9318. void __iomem *base = host->base;
  9319. - unsigned long flags;
  9320. u32 status;
  9321. status = readl(base + MMCISTATUS);
  9322. dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status);
  9323. - local_irq_save(flags);
  9324. -
  9325. do {
  9326. unsigned int remain, len;
  9327. char *buffer;
  9328. @@ -1203,8 +1200,6 @@
  9329. sg_miter_stop(sg_miter);
  9330. - local_irq_restore(flags);
  9331. -
  9332. /*
  9333. * If we have less than the fifo 'half-full' threshold to transfer,
  9334. * trigger a PIO interrupt as soon as any data is available.
  9335. diff -Nur linux-4.4.13.orig/drivers/net/ethernet/3com/3c59x.c linux-4.4.13/drivers/net/ethernet/3com/3c59x.c
  9336. --- linux-4.4.13.orig/drivers/net/ethernet/3com/3c59x.c 2016-06-08 03:14:51.000000000 +0200
  9337. +++ linux-4.4.13/drivers/net/ethernet/3com/3c59x.c 2016-06-22 21:55:08.010523867 +0200
  9338. @@ -842,9 +842,9 @@
  9339. {
  9340. struct vortex_private *vp = netdev_priv(dev);
  9341. unsigned long flags;
  9342. - local_irq_save(flags);
  9343. + local_irq_save_nort(flags);
  9344. (vp->full_bus_master_rx ? boomerang_interrupt:vortex_interrupt)(dev->irq,dev);
  9345. - local_irq_restore(flags);
  9346. + local_irq_restore_nort(flags);
  9347. }
  9348. #endif
  9349. @@ -1916,12 +1916,12 @@
  9350. * Block interrupts because vortex_interrupt does a bare spin_lock()
  9351. */
  9352. unsigned long flags;
  9353. - local_irq_save(flags);
  9354. + local_irq_save_nort(flags);
  9355. if (vp->full_bus_master_tx)
  9356. boomerang_interrupt(dev->irq, dev);
  9357. else
  9358. vortex_interrupt(dev->irq, dev);
  9359. - local_irq_restore(flags);
  9360. + local_irq_restore_nort(flags);
  9361. }
  9362. }
  9363. diff -Nur linux-4.4.13.orig/drivers/net/ethernet/atheros/atl1c/atl1c_main.c linux-4.4.13/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
  9364. --- linux-4.4.13.orig/drivers/net/ethernet/atheros/atl1c/atl1c_main.c 2016-06-08 03:14:51.000000000 +0200
  9365. +++ linux-4.4.13/drivers/net/ethernet/atheros/atl1c/atl1c_main.c 2016-06-22 21:55:08.010523867 +0200
  9366. @@ -2221,11 +2221,7 @@
  9367. }
  9368. tpd_req = atl1c_cal_tpd_req(skb);
  9369. - if (!spin_trylock_irqsave(&adapter->tx_lock, flags)) {
  9370. - if (netif_msg_pktdata(adapter))
  9371. - dev_info(&adapter->pdev->dev, "tx locked\n");
  9372. - return NETDEV_TX_LOCKED;
  9373. - }
  9374. + spin_lock_irqsave(&adapter->tx_lock, flags);
  9375. if (atl1c_tpd_avail(adapter, type) < tpd_req) {
  9376. /* no enough descriptor, just stop queue */
  9377. diff -Nur linux-4.4.13.orig/drivers/net/ethernet/atheros/atl1e/atl1e_main.c linux-4.4.13/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
  9378. --- linux-4.4.13.orig/drivers/net/ethernet/atheros/atl1e/atl1e_main.c 2016-06-08 03:14:51.000000000 +0200
  9379. +++ linux-4.4.13/drivers/net/ethernet/atheros/atl1e/atl1e_main.c 2016-06-22 21:55:08.010523867 +0200
  9380. @@ -1880,8 +1880,7 @@
  9381. return NETDEV_TX_OK;
  9382. }
  9383. tpd_req = atl1e_cal_tdp_req(skb);
  9384. - if (!spin_trylock_irqsave(&adapter->tx_lock, flags))
  9385. - return NETDEV_TX_LOCKED;
  9386. + spin_lock_irqsave(&adapter->tx_lock, flags);
  9387. if (atl1e_tpd_avail(adapter) < tpd_req) {
  9388. /* no enough descriptor, just stop queue */
  9389. diff -Nur linux-4.4.13.orig/drivers/net/ethernet/chelsio/cxgb/sge.c linux-4.4.13/drivers/net/ethernet/chelsio/cxgb/sge.c
  9390. --- linux-4.4.13.orig/drivers/net/ethernet/chelsio/cxgb/sge.c 2016-06-08 03:14:51.000000000 +0200
  9391. +++ linux-4.4.13/drivers/net/ethernet/chelsio/cxgb/sge.c 2016-06-22 21:55:08.014523867 +0200
  9392. @@ -1664,8 +1664,7 @@
  9393. struct cmdQ *q = &sge->cmdQ[qid];
  9394. unsigned int credits, pidx, genbit, count, use_sched_skb = 0;
  9395. - if (!spin_trylock(&q->lock))
  9396. - return NETDEV_TX_LOCKED;
  9397. + spin_lock(&q->lock);
  9398. reclaim_completed_tx(sge, q);
  9399. diff -Nur linux-4.4.13.orig/drivers/net/ethernet/neterion/s2io.c linux-4.4.13/drivers/net/ethernet/neterion/s2io.c
  9400. --- linux-4.4.13.orig/drivers/net/ethernet/neterion/s2io.c 2016-06-08 03:14:51.000000000 +0200
  9401. +++ linux-4.4.13/drivers/net/ethernet/neterion/s2io.c 2016-06-22 21:55:08.014523867 +0200
  9402. @@ -4084,12 +4084,7 @@
  9403. [skb->priority & (MAX_TX_FIFOS - 1)];
  9404. fifo = &mac_control->fifos[queue];
  9405. - if (do_spin_lock)
  9406. - spin_lock_irqsave(&fifo->tx_lock, flags);
  9407. - else {
  9408. - if (unlikely(!spin_trylock_irqsave(&fifo->tx_lock, flags)))
  9409. - return NETDEV_TX_LOCKED;
  9410. - }
  9411. + spin_lock_irqsave(&fifo->tx_lock, flags);
  9412. if (sp->config.multiq) {
  9413. if (__netif_subqueue_stopped(dev, fifo->fifo_no)) {
  9414. diff -Nur linux-4.4.13.orig/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c linux-4.4.13/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
  9415. --- linux-4.4.13.orig/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c 2016-06-08 03:14:51.000000000 +0200
  9416. +++ linux-4.4.13/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c 2016-06-22 21:55:08.014523867 +0200
  9417. @@ -2137,10 +2137,8 @@
  9418. struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
  9419. unsigned long flags;
  9420. - if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags)) {
  9421. - /* Collision - tell upper layer to requeue */
  9422. - return NETDEV_TX_LOCKED;
  9423. - }
  9424. + spin_lock_irqsave(&tx_ring->tx_lock, flags);
  9425. +
  9426. if (unlikely(!PCH_GBE_DESC_UNUSED(tx_ring))) {
  9427. netif_stop_queue(netdev);
  9428. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  9429. diff -Nur linux-4.4.13.orig/drivers/net/ethernet/realtek/8139too.c linux-4.4.13/drivers/net/ethernet/realtek/8139too.c
  9430. --- linux-4.4.13.orig/drivers/net/ethernet/realtek/8139too.c 2016-06-08 03:14:51.000000000 +0200
  9431. +++ linux-4.4.13/drivers/net/ethernet/realtek/8139too.c 2016-06-22 21:55:08.014523867 +0200
  9432. @@ -2229,7 +2229,7 @@
  9433. struct rtl8139_private *tp = netdev_priv(dev);
  9434. const int irq = tp->pci_dev->irq;
  9435. - disable_irq(irq);
  9436. + disable_irq_nosync(irq);
  9437. rtl8139_interrupt(irq, dev);
  9438. enable_irq(irq);
  9439. }
  9440. diff -Nur linux-4.4.13.orig/drivers/net/ethernet/tehuti/tehuti.c linux-4.4.13/drivers/net/ethernet/tehuti/tehuti.c
  9441. --- linux-4.4.13.orig/drivers/net/ethernet/tehuti/tehuti.c 2016-06-08 03:14:51.000000000 +0200
  9442. +++ linux-4.4.13/drivers/net/ethernet/tehuti/tehuti.c 2016-06-22 21:55:08.014523867 +0200
  9443. @@ -1629,13 +1629,8 @@
  9444. unsigned long flags;
  9445. ENTER;
  9446. - local_irq_save(flags);
  9447. - if (!spin_trylock(&priv->tx_lock)) {
  9448. - local_irq_restore(flags);
  9449. - DBG("%s[%s]: TX locked, returning NETDEV_TX_LOCKED\n",
  9450. - BDX_DRV_NAME, ndev->name);
  9451. - return NETDEV_TX_LOCKED;
  9452. - }
  9453. +
  9454. + spin_lock_irqsave(&priv->tx_lock, flags);
  9455. /* build tx descriptor */
  9456. BDX_ASSERT(f->m.wptr >= f->m.memsz); /* started with valid wptr */
  9457. diff -Nur linux-4.4.13.orig/drivers/net/rionet.c linux-4.4.13/drivers/net/rionet.c
  9458. --- linux-4.4.13.orig/drivers/net/rionet.c 2016-06-08 03:14:51.000000000 +0200
  9459. +++ linux-4.4.13/drivers/net/rionet.c 2016-06-22 21:55:08.014523867 +0200
  9460. @@ -174,11 +174,7 @@
  9461. unsigned long flags;
  9462. int add_num = 1;
  9463. - local_irq_save(flags);
  9464. - if (!spin_trylock(&rnet->tx_lock)) {
  9465. - local_irq_restore(flags);
  9466. - return NETDEV_TX_LOCKED;
  9467. - }
  9468. + spin_lock_irqsave(&rnet->tx_lock, flags);
  9469. if (is_multicast_ether_addr(eth->h_dest))
  9470. add_num = nets[rnet->mport->id].nact;
  9471. diff -Nur linux-4.4.13.orig/drivers/net/wireless/orinoco/orinoco_usb.c linux-4.4.13/drivers/net/wireless/orinoco/orinoco_usb.c
  9472. --- linux-4.4.13.orig/drivers/net/wireless/orinoco/orinoco_usb.c 2016-06-08 03:14:51.000000000 +0200
  9473. +++ linux-4.4.13/drivers/net/wireless/orinoco/orinoco_usb.c 2016-06-22 21:55:08.014523867 +0200
  9474. @@ -697,7 +697,7 @@
  9475. while (!ctx->done.done && msecs--)
  9476. udelay(1000);
  9477. } else {
  9478. - wait_event_interruptible(ctx->done.wait,
  9479. + swait_event_interruptible(ctx->done.wait,
  9480. ctx->done.done);
  9481. }
  9482. break;
  9483. diff -Nur linux-4.4.13.orig/drivers/pci/access.c linux-4.4.13/drivers/pci/access.c
  9484. --- linux-4.4.13.orig/drivers/pci/access.c 2016-06-08 03:14:51.000000000 +0200
  9485. +++ linux-4.4.13/drivers/pci/access.c 2016-06-22 21:55:08.014523867 +0200
  9486. @@ -561,7 +561,7 @@
  9487. WARN_ON(!dev->block_cfg_access);
  9488. dev->block_cfg_access = 0;
  9489. - wake_up_all(&pci_cfg_wait);
  9490. + wake_up_all_locked(&pci_cfg_wait);
  9491. raw_spin_unlock_irqrestore(&pci_lock, flags);
  9492. }
  9493. EXPORT_SYMBOL_GPL(pci_cfg_access_unlock);
  9494. diff -Nur linux-4.4.13.orig/drivers/scsi/fcoe/fcoe.c linux-4.4.13/drivers/scsi/fcoe/fcoe.c
  9495. --- linux-4.4.13.orig/drivers/scsi/fcoe/fcoe.c 2016-06-08 03:14:51.000000000 +0200
  9496. +++ linux-4.4.13/drivers/scsi/fcoe/fcoe.c 2016-06-22 21:55:08.018523867 +0200
  9497. @@ -1286,7 +1286,7 @@
  9498. struct sk_buff *skb;
  9499. #ifdef CONFIG_SMP
  9500. struct fcoe_percpu_s *p0;
  9501. - unsigned targ_cpu = get_cpu();
  9502. + unsigned targ_cpu = get_cpu_light();
  9503. #endif /* CONFIG_SMP */
  9504. FCOE_DBG("Destroying receive thread for CPU %d\n", cpu);
  9505. @@ -1342,7 +1342,7 @@
  9506. kfree_skb(skb);
  9507. spin_unlock_bh(&p->fcoe_rx_list.lock);
  9508. }
  9509. - put_cpu();
  9510. + put_cpu_light();
  9511. #else
  9512. /*
  9513. * This a non-SMP scenario where the singular Rx thread is
  9514. @@ -1566,11 +1566,11 @@
  9515. static int fcoe_alloc_paged_crc_eof(struct sk_buff *skb, int tlen)
  9516. {
  9517. struct fcoe_percpu_s *fps;
  9518. - int rc;
  9519. + int rc, cpu = get_cpu_light();
  9520. - fps = &get_cpu_var(fcoe_percpu);
  9521. + fps = &per_cpu(fcoe_percpu, cpu);
  9522. rc = fcoe_get_paged_crc_eof(skb, tlen, fps);
  9523. - put_cpu_var(fcoe_percpu);
  9524. + put_cpu_light();
  9525. return rc;
  9526. }
  9527. @@ -1766,11 +1766,11 @@
  9528. return 0;
  9529. }
  9530. - stats = per_cpu_ptr(lport->stats, get_cpu());
  9531. + stats = per_cpu_ptr(lport->stats, get_cpu_light());
  9532. stats->InvalidCRCCount++;
  9533. if (stats->InvalidCRCCount < 5)
  9534. printk(KERN_WARNING "fcoe: dropping frame with CRC error\n");
  9535. - put_cpu();
  9536. + put_cpu_light();
  9537. return -EINVAL;
  9538. }
  9539. @@ -1846,13 +1846,13 @@
  9540. goto drop;
  9541. if (!fcoe_filter_frames(lport, fp)) {
  9542. - put_cpu();
  9543. + put_cpu_light();
  9544. fc_exch_recv(lport, fp);
  9545. return;
  9546. }
  9547. drop:
  9548. stats->ErrorFrames++;
  9549. - put_cpu();
  9550. + put_cpu_light();
  9551. kfree_skb(skb);
  9552. }
  9553. diff -Nur linux-4.4.13.orig/drivers/scsi/fcoe/fcoe_ctlr.c linux-4.4.13/drivers/scsi/fcoe/fcoe_ctlr.c
  9554. --- linux-4.4.13.orig/drivers/scsi/fcoe/fcoe_ctlr.c 2016-06-08 03:14:51.000000000 +0200
  9555. +++ linux-4.4.13/drivers/scsi/fcoe/fcoe_ctlr.c 2016-06-22 21:55:08.018523867 +0200
  9556. @@ -831,7 +831,7 @@
  9557. INIT_LIST_HEAD(&del_list);
  9558. - stats = per_cpu_ptr(fip->lp->stats, get_cpu());
  9559. + stats = per_cpu_ptr(fip->lp->stats, get_cpu_light());
  9560. list_for_each_entry_safe(fcf, next, &fip->fcfs, list) {
  9561. deadline = fcf->time + fcf->fka_period + fcf->fka_period / 2;
  9562. @@ -867,7 +867,7 @@
  9563. sel_time = fcf->time;
  9564. }
  9565. }
  9566. - put_cpu();
  9567. + put_cpu_light();
  9568. list_for_each_entry_safe(fcf, next, &del_list, list) {
  9569. /* Removes fcf from current list */
  9570. diff -Nur linux-4.4.13.orig/drivers/scsi/libfc/fc_exch.c linux-4.4.13/drivers/scsi/libfc/fc_exch.c
  9571. --- linux-4.4.13.orig/drivers/scsi/libfc/fc_exch.c 2016-06-08 03:14:51.000000000 +0200
  9572. +++ linux-4.4.13/drivers/scsi/libfc/fc_exch.c 2016-06-22 21:55:08.018523867 +0200
  9573. @@ -814,10 +814,10 @@
  9574. }
  9575. memset(ep, 0, sizeof(*ep));
  9576. - cpu = get_cpu();
  9577. + cpu = get_cpu_light();
  9578. pool = per_cpu_ptr(mp->pool, cpu);
  9579. spin_lock_bh(&pool->lock);
  9580. - put_cpu();
  9581. + put_cpu_light();
  9582. /* peek cache of free slot */
  9583. if (pool->left != FC_XID_UNKNOWN) {
  9584. diff -Nur linux-4.4.13.orig/drivers/scsi/libsas/sas_ata.c linux-4.4.13/drivers/scsi/libsas/sas_ata.c
  9585. --- linux-4.4.13.orig/drivers/scsi/libsas/sas_ata.c 2016-06-08 03:14:51.000000000 +0200
  9586. +++ linux-4.4.13/drivers/scsi/libsas/sas_ata.c 2016-06-22 21:55:08.018523867 +0200
  9587. @@ -190,7 +190,7 @@
  9588. /* TODO: audit callers to ensure they are ready for qc_issue to
  9589. * unconditionally re-enable interrupts
  9590. */
  9591. - local_irq_save(flags);
  9592. + local_irq_save_nort(flags);
  9593. spin_unlock(ap->lock);
  9594. /* If the device fell off, no sense in issuing commands */
  9595. @@ -255,7 +255,7 @@
  9596. out:
  9597. spin_lock(ap->lock);
  9598. - local_irq_restore(flags);
  9599. + local_irq_restore_nort(flags);
  9600. return ret;
  9601. }
  9602. diff -Nur linux-4.4.13.orig/drivers/scsi/qla2xxx/qla_inline.h linux-4.4.13/drivers/scsi/qla2xxx/qla_inline.h
  9603. --- linux-4.4.13.orig/drivers/scsi/qla2xxx/qla_inline.h 2016-06-08 03:14:51.000000000 +0200
  9604. +++ linux-4.4.13/drivers/scsi/qla2xxx/qla_inline.h 2016-06-22 21:55:08.018523867 +0200
  9605. @@ -59,12 +59,12 @@
  9606. {
  9607. unsigned long flags;
  9608. struct qla_hw_data *ha = rsp->hw;
  9609. - local_irq_save(flags);
  9610. + local_irq_save_nort(flags);
  9611. if (IS_P3P_TYPE(ha))
  9612. qla82xx_poll(0, rsp);
  9613. else
  9614. ha->isp_ops->intr_handler(0, rsp);
  9615. - local_irq_restore(flags);
  9616. + local_irq_restore_nort(flags);
  9617. }
  9618. static inline uint8_t *
  9619. diff -Nur linux-4.4.13.orig/drivers/thermal/x86_pkg_temp_thermal.c linux-4.4.13/drivers/thermal/x86_pkg_temp_thermal.c
  9620. --- linux-4.4.13.orig/drivers/thermal/x86_pkg_temp_thermal.c 2016-06-08 03:14:51.000000000 +0200
  9621. +++ linux-4.4.13/drivers/thermal/x86_pkg_temp_thermal.c 2016-06-22 21:55:08.018523867 +0200
  9622. @@ -29,6 +29,7 @@
  9623. #include <linux/pm.h>
  9624. #include <linux/thermal.h>
  9625. #include <linux/debugfs.h>
  9626. +#include <linux/work-simple.h>
  9627. #include <asm/cpu_device_id.h>
  9628. #include <asm/mce.h>
  9629. @@ -352,7 +353,7 @@
  9630. }
  9631. }
  9632. -static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  9633. +static void platform_thermal_notify_work(struct swork_event *event)
  9634. {
  9635. unsigned long flags;
  9636. int cpu = smp_processor_id();
  9637. @@ -369,7 +370,7 @@
  9638. pkg_work_scheduled[phy_id]) {
  9639. disable_pkg_thres_interrupt();
  9640. spin_unlock_irqrestore(&pkg_work_lock, flags);
  9641. - return -EINVAL;
  9642. + return;
  9643. }
  9644. pkg_work_scheduled[phy_id] = 1;
  9645. spin_unlock_irqrestore(&pkg_work_lock, flags);
  9646. @@ -378,9 +379,48 @@
  9647. schedule_delayed_work_on(cpu,
  9648. &per_cpu(pkg_temp_thermal_threshold_work, cpu),
  9649. msecs_to_jiffies(notify_delay_ms));
  9650. +}
  9651. +
  9652. +#ifdef CONFIG_PREEMPT_RT_FULL
  9653. +static struct swork_event notify_work;
  9654. +
  9655. +static int thermal_notify_work_init(void)
  9656. +{
  9657. + int err;
  9658. +
  9659. + err = swork_get();
  9660. + if (err)
  9661. + return err;
  9662. +
  9663. + INIT_SWORK(&notify_work, platform_thermal_notify_work);
  9664. return 0;
  9665. }
  9666. +static void thermal_notify_work_cleanup(void)
  9667. +{
  9668. + swork_put();
  9669. +}
  9670. +
  9671. +static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  9672. +{
  9673. + swork_queue(&notify_work);
  9674. + return 0;
  9675. +}
  9676. +
  9677. +#else /* !CONFIG_PREEMPT_RT_FULL */
  9678. +
  9679. +static int thermal_notify_work_init(void) { return 0; }
  9680. +
  9681. +static void thermal_notify_work_cleanup(void) { }
  9682. +
  9683. +static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  9684. +{
  9685. + platform_thermal_notify_work(NULL);
  9686. +
  9687. + return 0;
  9688. +}
  9689. +#endif /* CONFIG_PREEMPT_RT_FULL */
  9690. +
  9691. static int find_siblings_cpu(int cpu)
  9692. {
  9693. int i;
  9694. @@ -584,6 +624,9 @@
  9695. if (!x86_match_cpu(pkg_temp_thermal_ids))
  9696. return -ENODEV;
  9697. + if (!thermal_notify_work_init())
  9698. + return -ENODEV;
  9699. +
  9700. spin_lock_init(&pkg_work_lock);
  9701. platform_thermal_package_notify =
  9702. pkg_temp_thermal_platform_thermal_notify;
  9703. @@ -608,7 +651,7 @@
  9704. kfree(pkg_work_scheduled);
  9705. platform_thermal_package_notify = NULL;
  9706. platform_thermal_package_rate_control = NULL;
  9707. -
  9708. + thermal_notify_work_cleanup();
  9709. return -ENODEV;
  9710. }
  9711. @@ -633,6 +676,7 @@
  9712. mutex_unlock(&phy_dev_list_mutex);
  9713. platform_thermal_package_notify = NULL;
  9714. platform_thermal_package_rate_control = NULL;
  9715. + thermal_notify_work_cleanup();
  9716. for_each_online_cpu(i)
  9717. cancel_delayed_work_sync(
  9718. &per_cpu(pkg_temp_thermal_threshold_work, i));
  9719. diff -Nur linux-4.4.13.orig/drivers/tty/serial/8250/8250_core.c linux-4.4.13/drivers/tty/serial/8250/8250_core.c
  9720. --- linux-4.4.13.orig/drivers/tty/serial/8250/8250_core.c 2016-06-08 03:14:51.000000000 +0200
  9721. +++ linux-4.4.13/drivers/tty/serial/8250/8250_core.c 2016-06-22 21:55:08.018523867 +0200
  9722. @@ -58,7 +58,16 @@
  9723. static unsigned int skip_txen_test; /* force skip of txen test at init time */
  9724. -#define PASS_LIMIT 512
  9725. +/*
  9726. + * On -rt we can have a more delays, and legitimately
  9727. + * so - so don't drop work spuriously and spam the
  9728. + * syslog:
  9729. + */
  9730. +#ifdef CONFIG_PREEMPT_RT_FULL
  9731. +# define PASS_LIMIT 1000000
  9732. +#else
  9733. +# define PASS_LIMIT 512
  9734. +#endif
  9735. #include <asm/serial.h>
  9736. /*
  9737. diff -Nur linux-4.4.13.orig/drivers/tty/serial/8250/8250_port.c linux-4.4.13/drivers/tty/serial/8250/8250_port.c
  9738. --- linux-4.4.13.orig/drivers/tty/serial/8250/8250_port.c 2016-06-08 03:14:51.000000000 +0200
  9739. +++ linux-4.4.13/drivers/tty/serial/8250/8250_port.c 2016-06-22 21:55:08.018523867 +0200
  9740. @@ -35,6 +35,7 @@
  9741. #include <linux/nmi.h>
  9742. #include <linux/mutex.h>
  9743. #include <linux/slab.h>
  9744. +#include <linux/kdb.h>
  9745. #include <linux/uaccess.h>
  9746. #include <linux/pm_runtime.h>
  9747. @@ -2843,9 +2844,9 @@
  9748. serial8250_rpm_get(up);
  9749. - if (port->sysrq)
  9750. + if (port->sysrq || oops_in_progress)
  9751. locked = 0;
  9752. - else if (oops_in_progress)
  9753. + else if (in_kdb_printk())
  9754. locked = spin_trylock_irqsave(&port->lock, flags);
  9755. else
  9756. spin_lock_irqsave(&port->lock, flags);
  9757. diff -Nur linux-4.4.13.orig/drivers/tty/serial/amba-pl011.c linux-4.4.13/drivers/tty/serial/amba-pl011.c
  9758. --- linux-4.4.13.orig/drivers/tty/serial/amba-pl011.c 2016-06-08 03:14:51.000000000 +0200
  9759. +++ linux-4.4.13/drivers/tty/serial/amba-pl011.c 2016-06-22 21:55:08.018523867 +0200
  9760. @@ -2067,13 +2067,19 @@
  9761. clk_enable(uap->clk);
  9762. - local_irq_save(flags);
  9763. + /*
  9764. + * local_irq_save(flags);
  9765. + *
  9766. + * This local_irq_save() is nonsense. If we come in via sysrq
  9767. + * handling then interrupts are already disabled. Aside of
  9768. + * that the port.sysrq check is racy on SMP regardless.
  9769. + */
  9770. if (uap->port.sysrq)
  9771. locked = 0;
  9772. else if (oops_in_progress)
  9773. - locked = spin_trylock(&uap->port.lock);
  9774. + locked = spin_trylock_irqsave(&uap->port.lock, flags);
  9775. else
  9776. - spin_lock(&uap->port.lock);
  9777. + spin_lock_irqsave(&uap->port.lock, flags);
  9778. /*
  9779. * First save the CR then disable the interrupts
  9780. @@ -2098,8 +2104,7 @@
  9781. writew(old_cr, uap->port.membase + UART011_CR);
  9782. if (locked)
  9783. - spin_unlock(&uap->port.lock);
  9784. - local_irq_restore(flags);
  9785. + spin_unlock_irqrestore(&uap->port.lock, flags);
  9786. clk_disable(uap->clk);
  9787. }
  9788. diff -Nur linux-4.4.13.orig/drivers/tty/serial/omap-serial.c linux-4.4.13/drivers/tty/serial/omap-serial.c
  9789. --- linux-4.4.13.orig/drivers/tty/serial/omap-serial.c 2016-06-08 03:14:51.000000000 +0200
  9790. +++ linux-4.4.13/drivers/tty/serial/omap-serial.c 2016-06-22 21:55:08.018523867 +0200
  9791. @@ -1257,13 +1257,10 @@
  9792. pm_runtime_get_sync(up->dev);
  9793. - local_irq_save(flags);
  9794. - if (up->port.sysrq)
  9795. - locked = 0;
  9796. - else if (oops_in_progress)
  9797. - locked = spin_trylock(&up->port.lock);
  9798. + if (up->port.sysrq || oops_in_progress)
  9799. + locked = spin_trylock_irqsave(&up->port.lock, flags);
  9800. else
  9801. - spin_lock(&up->port.lock);
  9802. + spin_lock_irqsave(&up->port.lock, flags);
  9803. /*
  9804. * First save the IER then disable the interrupts
  9805. @@ -1292,8 +1289,7 @@
  9806. pm_runtime_mark_last_busy(up->dev);
  9807. pm_runtime_put_autosuspend(up->dev);
  9808. if (locked)
  9809. - spin_unlock(&up->port.lock);
  9810. - local_irq_restore(flags);
  9811. + spin_unlock_irqrestore(&up->port.lock, flags);
  9812. }
  9813. static int __init
  9814. diff -Nur linux-4.4.13.orig/drivers/tty/serial/sc16is7xx.c linux-4.4.13/drivers/tty/serial/sc16is7xx.c
  9815. --- linux-4.4.13.orig/drivers/tty/serial/sc16is7xx.c 2016-06-08 03:14:51.000000000 +0200
  9816. +++ linux-4.4.13/drivers/tty/serial/sc16is7xx.c 2016-06-22 21:55:08.018523867 +0200
  9817. @@ -1230,7 +1230,7 @@
  9818. /* Setup interrupt */
  9819. ret = devm_request_irq(dev, irq, sc16is7xx_irq,
  9820. - IRQF_ONESHOT | flags, dev_name(dev), s);
  9821. + flags, dev_name(dev), s);
  9822. if (!ret)
  9823. return 0;
  9824. diff -Nur linux-4.4.13.orig/drivers/usb/core/hcd.c linux-4.4.13/drivers/usb/core/hcd.c
  9825. --- linux-4.4.13.orig/drivers/usb/core/hcd.c 2016-06-08 03:14:51.000000000 +0200
  9826. +++ linux-4.4.13/drivers/usb/core/hcd.c 2016-06-22 21:55:08.022523867 +0200
  9827. @@ -1735,9 +1735,9 @@
  9828. * and no one may trigger the above deadlock situation when
  9829. * running complete() in tasklet.
  9830. */
  9831. - local_irq_save(flags);
  9832. + local_irq_save_nort(flags);
  9833. urb->complete(urb);
  9834. - local_irq_restore(flags);
  9835. + local_irq_restore_nort(flags);
  9836. usb_anchor_resume_wakeups(anchor);
  9837. atomic_dec(&urb->use_count);
  9838. diff -Nur linux-4.4.13.orig/drivers/usb/gadget/function/f_fs.c linux-4.4.13/drivers/usb/gadget/function/f_fs.c
  9839. --- linux-4.4.13.orig/drivers/usb/gadget/function/f_fs.c 2016-06-08 03:14:51.000000000 +0200
  9840. +++ linux-4.4.13/drivers/usb/gadget/function/f_fs.c 2016-06-22 21:55:08.022523867 +0200
  9841. @@ -1404,7 +1404,7 @@
  9842. pr_info("%s(): freeing\n", __func__);
  9843. ffs_data_clear(ffs);
  9844. BUG_ON(waitqueue_active(&ffs->ev.waitq) ||
  9845. - waitqueue_active(&ffs->ep0req_completion.wait));
  9846. + swait_active(&ffs->ep0req_completion.wait));
  9847. kfree(ffs->dev_name);
  9848. kfree(ffs);
  9849. }
  9850. diff -Nur linux-4.4.13.orig/drivers/usb/gadget/legacy/inode.c linux-4.4.13/drivers/usb/gadget/legacy/inode.c
  9851. --- linux-4.4.13.orig/drivers/usb/gadget/legacy/inode.c 2016-06-08 03:14:51.000000000 +0200
  9852. +++ linux-4.4.13/drivers/usb/gadget/legacy/inode.c 2016-06-22 21:55:08.022523867 +0200
  9853. @@ -345,7 +345,7 @@
  9854. spin_unlock_irq (&epdata->dev->lock);
  9855. if (likely (value == 0)) {
  9856. - value = wait_event_interruptible (done.wait, done.done);
  9857. + value = swait_event_interruptible (done.wait, done.done);
  9858. if (value != 0) {
  9859. spin_lock_irq (&epdata->dev->lock);
  9860. if (likely (epdata->ep != NULL)) {
  9861. @@ -354,7 +354,7 @@
  9862. usb_ep_dequeue (epdata->ep, epdata->req);
  9863. spin_unlock_irq (&epdata->dev->lock);
  9864. - wait_event (done.wait, done.done);
  9865. + swait_event (done.wait, done.done);
  9866. if (epdata->status == -ECONNRESET)
  9867. epdata->status = -EINTR;
  9868. } else {
  9869. diff -Nur linux-4.4.13.orig/drivers/usb/gadget/udc/atmel_usba_udc.c linux-4.4.13/drivers/usb/gadget/udc/atmel_usba_udc.c
  9870. --- linux-4.4.13.orig/drivers/usb/gadget/udc/atmel_usba_udc.c 2016-06-08 03:14:51.000000000 +0200
  9871. +++ linux-4.4.13/drivers/usb/gadget/udc/atmel_usba_udc.c 2016-06-22 21:55:08.022523867 +0200
  9872. @@ -17,7 +17,9 @@
  9873. #include <linux/device.h>
  9874. #include <linux/dma-mapping.h>
  9875. #include <linux/list.h>
  9876. +#include <linux/mfd/syscon.h>
  9877. #include <linux/platform_device.h>
  9878. +#include <linux/regmap.h>
  9879. #include <linux/usb/ch9.h>
  9880. #include <linux/usb/gadget.h>
  9881. #include <linux/usb/atmel_usba_udc.h>
  9882. @@ -1888,20 +1890,15 @@
  9883. #ifdef CONFIG_OF
  9884. static void at91sam9rl_toggle_bias(struct usba_udc *udc, int is_on)
  9885. {
  9886. - unsigned int uckr = at91_pmc_read(AT91_CKGR_UCKR);
  9887. -
  9888. - if (is_on)
  9889. - at91_pmc_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN);
  9890. - else
  9891. - at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
  9892. + regmap_update_bits(udc->pmc, AT91_CKGR_UCKR, AT91_PMC_BIASEN,
  9893. + is_on ? AT91_PMC_BIASEN : 0);
  9894. }
  9895. static void at91sam9g45_pulse_bias(struct usba_udc *udc)
  9896. {
  9897. - unsigned int uckr = at91_pmc_read(AT91_CKGR_UCKR);
  9898. -
  9899. - at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
  9900. - at91_pmc_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN);
  9901. + regmap_update_bits(udc->pmc, AT91_CKGR_UCKR, AT91_PMC_BIASEN, 0);
  9902. + regmap_update_bits(udc->pmc, AT91_CKGR_UCKR, AT91_PMC_BIASEN,
  9903. + AT91_PMC_BIASEN);
  9904. }
  9905. static const struct usba_udc_errata at91sam9rl_errata = {
  9906. @@ -1938,6 +1935,9 @@
  9907. return ERR_PTR(-EINVAL);
  9908. udc->errata = match->data;
  9909. + udc->pmc = syscon_regmap_lookup_by_compatible("atmel,at91sam9g45-pmc");
  9910. + if (udc->errata && IS_ERR(udc->pmc))
  9911. + return ERR_CAST(udc->pmc);
  9912. udc->num_ep = 0;
  9913. diff -Nur linux-4.4.13.orig/drivers/usb/gadget/udc/atmel_usba_udc.h linux-4.4.13/drivers/usb/gadget/udc/atmel_usba_udc.h
  9914. --- linux-4.4.13.orig/drivers/usb/gadget/udc/atmel_usba_udc.h 2016-06-08 03:14:51.000000000 +0200
  9915. +++ linux-4.4.13/drivers/usb/gadget/udc/atmel_usba_udc.h 2016-06-22 21:55:08.022523867 +0200
  9916. @@ -354,6 +354,8 @@
  9917. struct dentry *debugfs_root;
  9918. struct dentry *debugfs_regs;
  9919. #endif
  9920. +
  9921. + struct regmap *pmc;
  9922. };
  9923. static inline struct usba_ep *to_usba_ep(struct usb_ep *ep)
  9924. diff -Nur linux-4.4.13.orig/fs/aio.c linux-4.4.13/fs/aio.c
  9925. --- linux-4.4.13.orig/fs/aio.c 2016-06-08 03:14:51.000000000 +0200
  9926. +++ linux-4.4.13/fs/aio.c 2016-06-22 21:55:08.022523867 +0200
  9927. @@ -40,6 +40,7 @@
  9928. #include <linux/ramfs.h>
  9929. #include <linux/percpu-refcount.h>
  9930. #include <linux/mount.h>
  9931. +#include <linux/work-simple.h>
  9932. #include <asm/kmap_types.h>
  9933. #include <asm/uaccess.h>
  9934. @@ -115,7 +116,7 @@
  9935. struct page **ring_pages;
  9936. long nr_pages;
  9937. - struct work_struct free_work;
  9938. + struct swork_event free_work;
  9939. /*
  9940. * signals when all in-flight requests are done
  9941. @@ -253,6 +254,7 @@
  9942. .mount = aio_mount,
  9943. .kill_sb = kill_anon_super,
  9944. };
  9945. + BUG_ON(swork_get());
  9946. aio_mnt = kern_mount(&aio_fs);
  9947. if (IS_ERR(aio_mnt))
  9948. panic("Failed to create aio fs mount.");
  9949. @@ -568,9 +570,9 @@
  9950. return cancel(&kiocb->common);
  9951. }
  9952. -static void free_ioctx(struct work_struct *work)
  9953. +static void free_ioctx(struct swork_event *sev)
  9954. {
  9955. - struct kioctx *ctx = container_of(work, struct kioctx, free_work);
  9956. + struct kioctx *ctx = container_of(sev, struct kioctx, free_work);
  9957. pr_debug("freeing %p\n", ctx);
  9958. @@ -589,8 +591,8 @@
  9959. if (ctx->rq_wait && atomic_dec_and_test(&ctx->rq_wait->count))
  9960. complete(&ctx->rq_wait->comp);
  9961. - INIT_WORK(&ctx->free_work, free_ioctx);
  9962. - schedule_work(&ctx->free_work);
  9963. + INIT_SWORK(&ctx->free_work, free_ioctx);
  9964. + swork_queue(&ctx->free_work);
  9965. }
  9966. /*
  9967. @@ -598,9 +600,9 @@
  9968. * and ctx->users has dropped to 0, so we know no more kiocbs can be submitted -
  9969. * now it's safe to cancel any that need to be.
  9970. */
  9971. -static void free_ioctx_users(struct percpu_ref *ref)
  9972. +static void free_ioctx_users_work(struct swork_event *sev)
  9973. {
  9974. - struct kioctx *ctx = container_of(ref, struct kioctx, users);
  9975. + struct kioctx *ctx = container_of(sev, struct kioctx, free_work);
  9976. struct aio_kiocb *req;
  9977. spin_lock_irq(&ctx->ctx_lock);
  9978. @@ -619,6 +621,14 @@
  9979. percpu_ref_put(&ctx->reqs);
  9980. }
  9981. +static void free_ioctx_users(struct percpu_ref *ref)
  9982. +{
  9983. + struct kioctx *ctx = container_of(ref, struct kioctx, users);
  9984. +
  9985. + INIT_SWORK(&ctx->free_work, free_ioctx_users_work);
  9986. + swork_queue(&ctx->free_work);
  9987. +}
  9988. +
  9989. static int ioctx_add_table(struct kioctx *ctx, struct mm_struct *mm)
  9990. {
  9991. unsigned i, new_nr;
  9992. diff -Nur linux-4.4.13.orig/fs/autofs4/autofs_i.h linux-4.4.13/fs/autofs4/autofs_i.h
  9993. --- linux-4.4.13.orig/fs/autofs4/autofs_i.h 2016-06-08 03:14:51.000000000 +0200
  9994. +++ linux-4.4.13/fs/autofs4/autofs_i.h 2016-06-22 21:55:08.022523867 +0200
  9995. @@ -34,6 +34,7 @@
  9996. #include <linux/sched.h>
  9997. #include <linux/mount.h>
  9998. #include <linux/namei.h>
  9999. +#include <linux/delay.h>
  10000. #include <asm/current.h>
  10001. #include <asm/uaccess.h>
  10002. diff -Nur linux-4.4.13.orig/fs/autofs4/expire.c linux-4.4.13/fs/autofs4/expire.c
  10003. --- linux-4.4.13.orig/fs/autofs4/expire.c 2016-06-08 03:14:51.000000000 +0200
  10004. +++ linux-4.4.13/fs/autofs4/expire.c 2016-06-22 21:55:08.022523867 +0200
  10005. @@ -150,7 +150,7 @@
  10006. parent = p->d_parent;
  10007. if (!spin_trylock(&parent->d_lock)) {
  10008. spin_unlock(&p->d_lock);
  10009. - cpu_relax();
  10010. + cpu_chill();
  10011. goto relock;
  10012. }
  10013. spin_unlock(&p->d_lock);
  10014. diff -Nur linux-4.4.13.orig/fs/buffer.c linux-4.4.13/fs/buffer.c
  10015. --- linux-4.4.13.orig/fs/buffer.c 2016-06-08 03:14:51.000000000 +0200
  10016. +++ linux-4.4.13/fs/buffer.c 2016-06-22 21:55:08.022523867 +0200
  10017. @@ -305,8 +305,7 @@
  10018. * decide that the page is now completely done.
  10019. */
  10020. first = page_buffers(page);
  10021. - local_irq_save(flags);
  10022. - bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
  10023. + flags = bh_uptodate_lock_irqsave(first);
  10024. clear_buffer_async_read(bh);
  10025. unlock_buffer(bh);
  10026. tmp = bh;
  10027. @@ -319,8 +318,7 @@
  10028. }
  10029. tmp = tmp->b_this_page;
  10030. } while (tmp != bh);
  10031. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  10032. - local_irq_restore(flags);
  10033. + bh_uptodate_unlock_irqrestore(first, flags);
  10034. /*
  10035. * If none of the buffers had errors and they are all
  10036. @@ -332,9 +330,7 @@
  10037. return;
  10038. still_busy:
  10039. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  10040. - local_irq_restore(flags);
  10041. - return;
  10042. + bh_uptodate_unlock_irqrestore(first, flags);
  10043. }
  10044. /*
  10045. @@ -362,8 +358,7 @@
  10046. }
  10047. first = page_buffers(page);
  10048. - local_irq_save(flags);
  10049. - bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
  10050. + flags = bh_uptodate_lock_irqsave(first);
  10051. clear_buffer_async_write(bh);
  10052. unlock_buffer(bh);
  10053. @@ -375,15 +370,12 @@
  10054. }
  10055. tmp = tmp->b_this_page;
  10056. }
  10057. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  10058. - local_irq_restore(flags);
  10059. + bh_uptodate_unlock_irqrestore(first, flags);
  10060. end_page_writeback(page);
  10061. return;
  10062. still_busy:
  10063. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  10064. - local_irq_restore(flags);
  10065. - return;
  10066. + bh_uptodate_unlock_irqrestore(first, flags);
  10067. }
  10068. EXPORT_SYMBOL(end_buffer_async_write);
  10069. @@ -3325,6 +3317,7 @@
  10070. struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags);
  10071. if (ret) {
  10072. INIT_LIST_HEAD(&ret->b_assoc_buffers);
  10073. + buffer_head_init_locks(ret);
  10074. preempt_disable();
  10075. __this_cpu_inc(bh_accounting.nr);
  10076. recalc_bh_state();
  10077. diff -Nur linux-4.4.13.orig/fs/dcache.c linux-4.4.13/fs/dcache.c
  10078. --- linux-4.4.13.orig/fs/dcache.c 2016-06-08 03:14:51.000000000 +0200
  10079. +++ linux-4.4.13/fs/dcache.c 2016-06-22 21:55:08.022523867 +0200
  10080. @@ -19,6 +19,7 @@
  10081. #include <linux/mm.h>
  10082. #include <linux/fs.h>
  10083. #include <linux/fsnotify.h>
  10084. +#include <linux/delay.h>
  10085. #include <linux/slab.h>
  10086. #include <linux/init.h>
  10087. #include <linux/hash.h>
  10088. @@ -578,7 +579,7 @@
  10089. failed:
  10090. spin_unlock(&dentry->d_lock);
  10091. - cpu_relax();
  10092. + cpu_chill();
  10093. return dentry; /* try again with same dentry */
  10094. }
  10095. @@ -2391,7 +2392,7 @@
  10096. if (dentry->d_lockref.count == 1) {
  10097. if (!spin_trylock(&inode->i_lock)) {
  10098. spin_unlock(&dentry->d_lock);
  10099. - cpu_relax();
  10100. + cpu_chill();
  10101. goto again;
  10102. }
  10103. dentry->d_flags &= ~DCACHE_CANT_MOUNT;
  10104. diff -Nur linux-4.4.13.orig/fs/eventpoll.c linux-4.4.13/fs/eventpoll.c
  10105. --- linux-4.4.13.orig/fs/eventpoll.c 2016-06-08 03:14:51.000000000 +0200
  10106. +++ linux-4.4.13/fs/eventpoll.c 2016-06-22 21:55:08.026523867 +0200
  10107. @@ -505,12 +505,12 @@
  10108. */
  10109. static void ep_poll_safewake(wait_queue_head_t *wq)
  10110. {
  10111. - int this_cpu = get_cpu();
  10112. + int this_cpu = get_cpu_light();
  10113. ep_call_nested(&poll_safewake_ncalls, EP_MAX_NESTS,
  10114. ep_poll_wakeup_proc, NULL, wq, (void *) (long) this_cpu);
  10115. - put_cpu();
  10116. + put_cpu_light();
  10117. }
  10118. static void ep_remove_wait_queue(struct eppoll_entry *pwq)
  10119. diff -Nur linux-4.4.13.orig/fs/exec.c linux-4.4.13/fs/exec.c
  10120. --- linux-4.4.13.orig/fs/exec.c 2016-06-08 03:14:51.000000000 +0200
  10121. +++ linux-4.4.13/fs/exec.c 2016-06-22 21:55:08.026523867 +0200
  10122. @@ -865,12 +865,14 @@
  10123. }
  10124. }
  10125. task_lock(tsk);
  10126. + preempt_disable_rt();
  10127. active_mm = tsk->active_mm;
  10128. tsk->mm = mm;
  10129. tsk->active_mm = mm;
  10130. activate_mm(active_mm, mm);
  10131. tsk->mm->vmacache_seqnum = 0;
  10132. vmacache_flush(tsk);
  10133. + preempt_enable_rt();
  10134. task_unlock(tsk);
  10135. if (old_mm) {
  10136. up_read(&old_mm->mmap_sem);
  10137. diff -Nur linux-4.4.13.orig/fs/f2fs/f2fs.h linux-4.4.13/fs/f2fs/f2fs.h
  10138. --- linux-4.4.13.orig/fs/f2fs/f2fs.h 2016-06-08 03:14:51.000000000 +0200
  10139. +++ linux-4.4.13/fs/f2fs/f2fs.h 2016-06-22 21:55:08.026523867 +0200
  10140. @@ -24,7 +24,6 @@
  10141. #ifdef CONFIG_F2FS_CHECK_FS
  10142. #define f2fs_bug_on(sbi, condition) BUG_ON(condition)
  10143. -#define f2fs_down_write(x, y) down_write_nest_lock(x, y)
  10144. #else
  10145. #define f2fs_bug_on(sbi, condition) \
  10146. do { \
  10147. @@ -33,7 +32,6 @@
  10148. set_sbi_flag(sbi, SBI_NEED_FSCK); \
  10149. } \
  10150. } while (0)
  10151. -#define f2fs_down_write(x, y) down_write(x)
  10152. #endif
  10153. /*
  10154. @@ -959,7 +957,7 @@
  10155. static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
  10156. {
  10157. - f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex);
  10158. + down_write(&sbi->cp_rwsem);
  10159. }
  10160. static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
  10161. diff -Nur linux-4.4.13.orig/fs/jbd2/checkpoint.c linux-4.4.13/fs/jbd2/checkpoint.c
  10162. --- linux-4.4.13.orig/fs/jbd2/checkpoint.c 2016-06-08 03:14:51.000000000 +0200
  10163. +++ linux-4.4.13/fs/jbd2/checkpoint.c 2016-06-22 21:55:08.026523867 +0200
  10164. @@ -116,6 +116,8 @@
  10165. nblocks = jbd2_space_needed(journal);
  10166. while (jbd2_log_space_left(journal) < nblocks) {
  10167. write_unlock(&journal->j_state_lock);
  10168. + if (current->plug)
  10169. + io_schedule();
  10170. mutex_lock(&journal->j_checkpoint_mutex);
  10171. /*
  10172. diff -Nur linux-4.4.13.orig/fs/namespace.c linux-4.4.13/fs/namespace.c
  10173. --- linux-4.4.13.orig/fs/namespace.c 2016-06-08 03:14:51.000000000 +0200
  10174. +++ linux-4.4.13/fs/namespace.c 2016-06-22 21:55:08.026523867 +0200
  10175. @@ -14,6 +14,7 @@
  10176. #include <linux/mnt_namespace.h>
  10177. #include <linux/user_namespace.h>
  10178. #include <linux/namei.h>
  10179. +#include <linux/delay.h>
  10180. #include <linux/security.h>
  10181. #include <linux/idr.h>
  10182. #include <linux/init.h> /* init_rootfs */
  10183. @@ -353,8 +354,11 @@
  10184. * incremented count after it has set MNT_WRITE_HOLD.
  10185. */
  10186. smp_mb();
  10187. - while (ACCESS_ONCE(mnt->mnt.mnt_flags) & MNT_WRITE_HOLD)
  10188. - cpu_relax();
  10189. + while (ACCESS_ONCE(mnt->mnt.mnt_flags) & MNT_WRITE_HOLD) {
  10190. + preempt_enable();
  10191. + cpu_chill();
  10192. + preempt_disable();
  10193. + }
  10194. /*
  10195. * After the slowpath clears MNT_WRITE_HOLD, mnt_is_readonly will
  10196. * be set to match its requirements. So we must not load that until
  10197. diff -Nur linux-4.4.13.orig/fs/ntfs/aops.c linux-4.4.13/fs/ntfs/aops.c
  10198. --- linux-4.4.13.orig/fs/ntfs/aops.c 2016-06-08 03:14:51.000000000 +0200
  10199. +++ linux-4.4.13/fs/ntfs/aops.c 2016-06-22 21:55:08.026523867 +0200
  10200. @@ -107,8 +107,7 @@
  10201. "0x%llx.", (unsigned long long)bh->b_blocknr);
  10202. }
  10203. first = page_buffers(page);
  10204. - local_irq_save(flags);
  10205. - bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
  10206. + flags = bh_uptodate_lock_irqsave(first);
  10207. clear_buffer_async_read(bh);
  10208. unlock_buffer(bh);
  10209. tmp = bh;
  10210. @@ -123,8 +122,7 @@
  10211. }
  10212. tmp = tmp->b_this_page;
  10213. } while (tmp != bh);
  10214. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  10215. - local_irq_restore(flags);
  10216. + bh_uptodate_unlock_irqrestore(first, flags);
  10217. /*
  10218. * If none of the buffers had errors then we can set the page uptodate,
  10219. * but we first have to perform the post read mst fixups, if the
  10220. @@ -145,13 +143,13 @@
  10221. recs = PAGE_CACHE_SIZE / rec_size;
  10222. /* Should have been verified before we got here... */
  10223. BUG_ON(!recs);
  10224. - local_irq_save(flags);
  10225. + local_irq_save_nort(flags);
  10226. kaddr = kmap_atomic(page);
  10227. for (i = 0; i < recs; i++)
  10228. post_read_mst_fixup((NTFS_RECORD*)(kaddr +
  10229. i * rec_size), rec_size);
  10230. kunmap_atomic(kaddr);
  10231. - local_irq_restore(flags);
  10232. + local_irq_restore_nort(flags);
  10233. flush_dcache_page(page);
  10234. if (likely(page_uptodate && !PageError(page)))
  10235. SetPageUptodate(page);
  10236. @@ -159,9 +157,7 @@
  10237. unlock_page(page);
  10238. return;
  10239. still_busy:
  10240. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  10241. - local_irq_restore(flags);
  10242. - return;
  10243. + bh_uptodate_unlock_irqrestore(first, flags);
  10244. }
  10245. /**
  10246. diff -Nur linux-4.4.13.orig/fs/timerfd.c linux-4.4.13/fs/timerfd.c
  10247. --- linux-4.4.13.orig/fs/timerfd.c 2016-06-08 03:14:51.000000000 +0200
  10248. +++ linux-4.4.13/fs/timerfd.c 2016-06-22 21:55:08.026523867 +0200
  10249. @@ -450,7 +450,10 @@
  10250. break;
  10251. }
  10252. spin_unlock_irq(&ctx->wqh.lock);
  10253. - cpu_relax();
  10254. + if (isalarm(ctx))
  10255. + hrtimer_wait_for_timer(&ctx->t.alarm.timer);
  10256. + else
  10257. + hrtimer_wait_for_timer(&ctx->t.tmr);
  10258. }
  10259. /*
  10260. diff -Nur linux-4.4.13.orig/include/acpi/platform/aclinux.h linux-4.4.13/include/acpi/platform/aclinux.h
  10261. --- linux-4.4.13.orig/include/acpi/platform/aclinux.h 2016-06-08 03:14:51.000000000 +0200
  10262. +++ linux-4.4.13/include/acpi/platform/aclinux.h 2016-06-22 21:55:08.026523867 +0200
  10263. @@ -127,6 +127,7 @@
  10264. #define acpi_cache_t struct kmem_cache
  10265. #define acpi_spinlock spinlock_t *
  10266. +#define acpi_raw_spinlock raw_spinlock_t *
  10267. #define acpi_cpu_flags unsigned long
  10268. /* Use native linux version of acpi_os_allocate_zeroed */
  10269. @@ -145,6 +146,20 @@
  10270. #define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_thread_id
  10271. #define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_create_lock
  10272. +#define acpi_os_create_raw_lock(__handle) \
  10273. +({ \
  10274. + raw_spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
  10275. + \
  10276. + if (lock) { \
  10277. + *(__handle) = lock; \
  10278. + raw_spin_lock_init(*(__handle)); \
  10279. + } \
  10280. + lock ? AE_OK : AE_NO_MEMORY; \
  10281. + })
  10282. +
  10283. +#define acpi_os_delete_raw_lock(__handle) kfree(__handle)
  10284. +
  10285. +
  10286. /*
  10287. * OSL interfaces used by debugger/disassembler
  10288. */
  10289. diff -Nur linux-4.4.13.orig/include/asm-generic/bug.h linux-4.4.13/include/asm-generic/bug.h
  10290. --- linux-4.4.13.orig/include/asm-generic/bug.h 2016-06-08 03:14:51.000000000 +0200
  10291. +++ linux-4.4.13/include/asm-generic/bug.h 2016-06-22 21:55:08.026523867 +0200
  10292. @@ -206,6 +206,20 @@
  10293. # define WARN_ON_SMP(x) ({0;})
  10294. #endif
  10295. +#ifdef CONFIG_PREEMPT_RT_BASE
  10296. +# define BUG_ON_RT(c) BUG_ON(c)
  10297. +# define BUG_ON_NONRT(c) do { } while (0)
  10298. +# define WARN_ON_RT(condition) WARN_ON(condition)
  10299. +# define WARN_ON_NONRT(condition) do { } while (0)
  10300. +# define WARN_ON_ONCE_NONRT(condition) do { } while (0)
  10301. +#else
  10302. +# define BUG_ON_RT(c) do { } while (0)
  10303. +# define BUG_ON_NONRT(c) BUG_ON(c)
  10304. +# define WARN_ON_RT(condition) do { } while (0)
  10305. +# define WARN_ON_NONRT(condition) WARN_ON(condition)
  10306. +# define WARN_ON_ONCE_NONRT(condition) WARN_ON_ONCE(condition)
  10307. +#endif
  10308. +
  10309. #endif /* __ASSEMBLY__ */
  10310. #endif
  10311. diff -Nur linux-4.4.13.orig/include/asm-generic/preempt.h linux-4.4.13/include/asm-generic/preempt.h
  10312. --- linux-4.4.13.orig/include/asm-generic/preempt.h 2016-06-08 03:14:51.000000000 +0200
  10313. +++ linux-4.4.13/include/asm-generic/preempt.h 2016-06-22 21:55:08.026523867 +0200
  10314. @@ -7,10 +7,10 @@
  10315. static __always_inline int preempt_count(void)
  10316. {
  10317. - return current_thread_info()->preempt_count;
  10318. + return READ_ONCE(current_thread_info()->preempt_count);
  10319. }
  10320. -static __always_inline int *preempt_count_ptr(void)
  10321. +static __always_inline volatile int *preempt_count_ptr(void)
  10322. {
  10323. return &current_thread_info()->preempt_count;
  10324. }
  10325. diff -Nur linux-4.4.13.orig/include/linux/blkdev.h linux-4.4.13/include/linux/blkdev.h
  10326. --- linux-4.4.13.orig/include/linux/blkdev.h 2016-06-08 03:14:51.000000000 +0200
  10327. +++ linux-4.4.13/include/linux/blkdev.h 2016-06-22 21:55:08.026523867 +0200
  10328. @@ -89,6 +89,7 @@
  10329. struct list_head queuelist;
  10330. union {
  10331. struct call_single_data csd;
  10332. + struct work_struct work;
  10333. unsigned long fifo_time;
  10334. };
  10335. @@ -455,7 +456,7 @@
  10336. struct throtl_data *td;
  10337. #endif
  10338. struct rcu_head rcu_head;
  10339. - wait_queue_head_t mq_freeze_wq;
  10340. + struct swait_queue_head mq_freeze_wq;
  10341. struct percpu_ref q_usage_counter;
  10342. struct list_head all_q_node;
  10343. diff -Nur linux-4.4.13.orig/include/linux/blk-mq.h linux-4.4.13/include/linux/blk-mq.h
  10344. --- linux-4.4.13.orig/include/linux/blk-mq.h 2016-06-08 03:14:51.000000000 +0200
  10345. +++ linux-4.4.13/include/linux/blk-mq.h 2016-06-22 21:55:08.026523867 +0200
  10346. @@ -212,6 +212,7 @@
  10347. struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index);
  10348. struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int, int);
  10349. +void __blk_mq_complete_request_remote_work(struct work_struct *work);
  10350. int blk_mq_request_started(struct request *rq);
  10351. void blk_mq_start_request(struct request *rq);
  10352. diff -Nur linux-4.4.13.orig/include/linux/bottom_half.h linux-4.4.13/include/linux/bottom_half.h
  10353. --- linux-4.4.13.orig/include/linux/bottom_half.h 2016-06-08 03:14:51.000000000 +0200
  10354. +++ linux-4.4.13/include/linux/bottom_half.h 2016-06-22 21:55:08.026523867 +0200
  10355. @@ -3,6 +3,39 @@
  10356. #include <linux/preempt.h>
  10357. +#ifdef CONFIG_PREEMPT_RT_FULL
  10358. +
  10359. +extern void __local_bh_disable(void);
  10360. +extern void _local_bh_enable(void);
  10361. +extern void __local_bh_enable(void);
  10362. +
  10363. +static inline void local_bh_disable(void)
  10364. +{
  10365. + __local_bh_disable();
  10366. +}
  10367. +
  10368. +static inline void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
  10369. +{
  10370. + __local_bh_disable();
  10371. +}
  10372. +
  10373. +static inline void local_bh_enable(void)
  10374. +{
  10375. + __local_bh_enable();
  10376. +}
  10377. +
  10378. +static inline void __local_bh_enable_ip(unsigned long ip, unsigned int cnt)
  10379. +{
  10380. + __local_bh_enable();
  10381. +}
  10382. +
  10383. +static inline void local_bh_enable_ip(unsigned long ip)
  10384. +{
  10385. + __local_bh_enable();
  10386. +}
  10387. +
  10388. +#else
  10389. +
  10390. #ifdef CONFIG_TRACE_IRQFLAGS
  10391. extern void __local_bh_disable_ip(unsigned long ip, unsigned int cnt);
  10392. #else
  10393. @@ -30,5 +63,6 @@
  10394. {
  10395. __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
  10396. }
  10397. +#endif
  10398. #endif /* _LINUX_BH_H */
  10399. diff -Nur linux-4.4.13.orig/include/linux/buffer_head.h linux-4.4.13/include/linux/buffer_head.h
  10400. --- linux-4.4.13.orig/include/linux/buffer_head.h 2016-06-08 03:14:51.000000000 +0200
  10401. +++ linux-4.4.13/include/linux/buffer_head.h 2016-06-22 21:55:08.026523867 +0200
  10402. @@ -75,8 +75,50 @@
  10403. struct address_space *b_assoc_map; /* mapping this buffer is
  10404. associated with */
  10405. atomic_t b_count; /* users using this buffer_head */
  10406. +#ifdef CONFIG_PREEMPT_RT_BASE
  10407. + spinlock_t b_uptodate_lock;
  10408. +#if IS_ENABLED(CONFIG_JBD2)
  10409. + spinlock_t b_state_lock;
  10410. + spinlock_t b_journal_head_lock;
  10411. +#endif
  10412. +#endif
  10413. };
  10414. +static inline unsigned long bh_uptodate_lock_irqsave(struct buffer_head *bh)
  10415. +{
  10416. + unsigned long flags;
  10417. +
  10418. +#ifndef CONFIG_PREEMPT_RT_BASE
  10419. + local_irq_save(flags);
  10420. + bit_spin_lock(BH_Uptodate_Lock, &bh->b_state);
  10421. +#else
  10422. + spin_lock_irqsave(&bh->b_uptodate_lock, flags);
  10423. +#endif
  10424. + return flags;
  10425. +}
  10426. +
  10427. +static inline void
  10428. +bh_uptodate_unlock_irqrestore(struct buffer_head *bh, unsigned long flags)
  10429. +{
  10430. +#ifndef CONFIG_PREEMPT_RT_BASE
  10431. + bit_spin_unlock(BH_Uptodate_Lock, &bh->b_state);
  10432. + local_irq_restore(flags);
  10433. +#else
  10434. + spin_unlock_irqrestore(&bh->b_uptodate_lock, flags);
  10435. +#endif
  10436. +}
  10437. +
  10438. +static inline void buffer_head_init_locks(struct buffer_head *bh)
  10439. +{
  10440. +#ifdef CONFIG_PREEMPT_RT_BASE
  10441. + spin_lock_init(&bh->b_uptodate_lock);
  10442. +#if IS_ENABLED(CONFIG_JBD2)
  10443. + spin_lock_init(&bh->b_state_lock);
  10444. + spin_lock_init(&bh->b_journal_head_lock);
  10445. +#endif
  10446. +#endif
  10447. +}
  10448. +
  10449. /*
  10450. * macro tricks to expand the set_buffer_foo(), clear_buffer_foo()
  10451. * and buffer_foo() functions.
  10452. diff -Nur linux-4.4.13.orig/include/linux/cgroup-defs.h linux-4.4.13/include/linux/cgroup-defs.h
  10453. --- linux-4.4.13.orig/include/linux/cgroup-defs.h 2016-06-08 03:14:51.000000000 +0200
  10454. +++ linux-4.4.13/include/linux/cgroup-defs.h 2016-06-22 21:55:08.026523867 +0200
  10455. @@ -16,6 +16,7 @@
  10456. #include <linux/percpu-refcount.h>
  10457. #include <linux/percpu-rwsem.h>
  10458. #include <linux/workqueue.h>
  10459. +#include <linux/work-simple.h>
  10460. #ifdef CONFIG_CGROUPS
  10461. @@ -142,6 +143,7 @@
  10462. /* percpu_ref killing and RCU release */
  10463. struct rcu_head rcu_head;
  10464. struct work_struct destroy_work;
  10465. + struct swork_event destroy_swork;
  10466. };
  10467. /*
  10468. diff -Nur linux-4.4.13.orig/include/linux/clk/at91_pmc.h linux-4.4.13/include/linux/clk/at91_pmc.h
  10469. --- linux-4.4.13.orig/include/linux/clk/at91_pmc.h 2016-06-08 03:14:51.000000000 +0200
  10470. +++ linux-4.4.13/include/linux/clk/at91_pmc.h 2016-06-22 21:55:08.026523867 +0200
  10471. @@ -16,18 +16,6 @@
  10472. #ifndef AT91_PMC_H
  10473. #define AT91_PMC_H
  10474. -#ifndef __ASSEMBLY__
  10475. -extern void __iomem *at91_pmc_base;
  10476. -
  10477. -#define at91_pmc_read(field) \
  10478. - readl_relaxed(at91_pmc_base + field)
  10479. -
  10480. -#define at91_pmc_write(field, value) \
  10481. - writel_relaxed(value, at91_pmc_base + field)
  10482. -#else
  10483. -.extern at91_pmc_base
  10484. -#endif
  10485. -
  10486. #define AT91_PMC_SCER 0x00 /* System Clock Enable Register */
  10487. #define AT91_PMC_SCDR 0x04 /* System Clock Disable Register */
  10488. diff -Nur linux-4.4.13.orig/include/linux/completion.h linux-4.4.13/include/linux/completion.h
  10489. --- linux-4.4.13.orig/include/linux/completion.h 2016-06-08 03:14:51.000000000 +0200
  10490. +++ linux-4.4.13/include/linux/completion.h 2016-06-22 21:55:08.030523867 +0200
  10491. @@ -7,8 +7,7 @@
  10492. * Atomic wait-for-completion handler data structures.
  10493. * See kernel/sched/completion.c for details.
  10494. */
  10495. -
  10496. -#include <linux/wait.h>
  10497. +#include <linux/swait.h>
  10498. /*
  10499. * struct completion - structure used to maintain state for a "completion"
  10500. @@ -24,11 +23,11 @@
  10501. */
  10502. struct completion {
  10503. unsigned int done;
  10504. - wait_queue_head_t wait;
  10505. + struct swait_queue_head wait;
  10506. };
  10507. #define COMPLETION_INITIALIZER(work) \
  10508. - { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
  10509. + { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
  10510. #define COMPLETION_INITIALIZER_ONSTACK(work) \
  10511. ({ init_completion(&work); work; })
  10512. @@ -73,7 +72,7 @@
  10513. static inline void init_completion(struct completion *x)
  10514. {
  10515. x->done = 0;
  10516. - init_waitqueue_head(&x->wait);
  10517. + init_swait_queue_head(&x->wait);
  10518. }
  10519. /**
  10520. diff -Nur linux-4.4.13.orig/include/linux/cpu.h linux-4.4.13/include/linux/cpu.h
  10521. --- linux-4.4.13.orig/include/linux/cpu.h 2016-06-08 03:14:51.000000000 +0200
  10522. +++ linux-4.4.13/include/linux/cpu.h 2016-06-22 21:55:08.030523867 +0200
  10523. @@ -231,6 +231,8 @@
  10524. extern void put_online_cpus(void);
  10525. extern void cpu_hotplug_disable(void);
  10526. extern void cpu_hotplug_enable(void);
  10527. +extern void pin_current_cpu(void);
  10528. +extern void unpin_current_cpu(void);
  10529. #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
  10530. #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
  10531. #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
  10532. @@ -248,6 +250,8 @@
  10533. #define put_online_cpus() do { } while (0)
  10534. #define cpu_hotplug_disable() do { } while (0)
  10535. #define cpu_hotplug_enable() do { } while (0)
  10536. +static inline void pin_current_cpu(void) { }
  10537. +static inline void unpin_current_cpu(void) { }
  10538. #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  10539. #define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  10540. /* These aren't inline functions due to a GCC bug. */
  10541. diff -Nur linux-4.4.13.orig/include/linux/delay.h linux-4.4.13/include/linux/delay.h
  10542. --- linux-4.4.13.orig/include/linux/delay.h 2016-06-08 03:14:51.000000000 +0200
  10543. +++ linux-4.4.13/include/linux/delay.h 2016-06-22 21:55:08.030523867 +0200
  10544. @@ -52,4 +52,10 @@
  10545. msleep(seconds * 1000);
  10546. }
  10547. +#ifdef CONFIG_PREEMPT_RT_FULL
  10548. +extern void cpu_chill(void);
  10549. +#else
  10550. +# define cpu_chill() cpu_relax()
  10551. +#endif
  10552. +
  10553. #endif /* defined(_LINUX_DELAY_H) */
  10554. diff -Nur linux-4.4.13.orig/include/linux/ftrace.h linux-4.4.13/include/linux/ftrace.h
  10555. --- linux-4.4.13.orig/include/linux/ftrace.h 2016-06-08 03:14:51.000000000 +0200
  10556. +++ linux-4.4.13/include/linux/ftrace.h 2016-06-22 21:55:08.030523867 +0200
  10557. @@ -694,6 +694,18 @@
  10558. #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
  10559. #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
  10560. +static inline unsigned long get_lock_parent_ip(void)
  10561. +{
  10562. + unsigned long addr = CALLER_ADDR0;
  10563. +
  10564. + if (!in_lock_functions(addr))
  10565. + return addr;
  10566. + addr = CALLER_ADDR1;
  10567. + if (!in_lock_functions(addr))
  10568. + return addr;
  10569. + return CALLER_ADDR2;
  10570. +}
  10571. +
  10572. #ifdef CONFIG_IRQSOFF_TRACER
  10573. extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
  10574. extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
  10575. diff -Nur linux-4.4.13.orig/include/linux/highmem.h linux-4.4.13/include/linux/highmem.h
  10576. --- linux-4.4.13.orig/include/linux/highmem.h 2016-06-08 03:14:51.000000000 +0200
  10577. +++ linux-4.4.13/include/linux/highmem.h 2016-06-22 21:55:08.030523867 +0200
  10578. @@ -7,6 +7,7 @@
  10579. #include <linux/mm.h>
  10580. #include <linux/uaccess.h>
  10581. #include <linux/hardirq.h>
  10582. +#include <linux/sched.h>
  10583. #include <asm/cacheflush.h>
  10584. @@ -65,7 +66,7 @@
  10585. static inline void *kmap_atomic(struct page *page)
  10586. {
  10587. - preempt_disable();
  10588. + preempt_disable_nort();
  10589. pagefault_disable();
  10590. return page_address(page);
  10591. }
  10592. @@ -74,7 +75,7 @@
  10593. static inline void __kunmap_atomic(void *addr)
  10594. {
  10595. pagefault_enable();
  10596. - preempt_enable();
  10597. + preempt_enable_nort();
  10598. }
  10599. #define kmap_atomic_pfn(pfn) kmap_atomic(pfn_to_page(pfn))
  10600. @@ -86,32 +87,51 @@
  10601. #if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
  10602. +#ifndef CONFIG_PREEMPT_RT_FULL
  10603. DECLARE_PER_CPU(int, __kmap_atomic_idx);
  10604. +#endif
  10605. static inline int kmap_atomic_idx_push(void)
  10606. {
  10607. +#ifndef CONFIG_PREEMPT_RT_FULL
  10608. int idx = __this_cpu_inc_return(__kmap_atomic_idx) - 1;
  10609. -#ifdef CONFIG_DEBUG_HIGHMEM
  10610. +# ifdef CONFIG_DEBUG_HIGHMEM
  10611. WARN_ON_ONCE(in_irq() && !irqs_disabled());
  10612. BUG_ON(idx >= KM_TYPE_NR);
  10613. -#endif
  10614. +# endif
  10615. return idx;
  10616. +#else
  10617. + current->kmap_idx++;
  10618. + BUG_ON(current->kmap_idx > KM_TYPE_NR);
  10619. + return current->kmap_idx - 1;
  10620. +#endif
  10621. }
  10622. static inline int kmap_atomic_idx(void)
  10623. {
  10624. +#ifndef CONFIG_PREEMPT_RT_FULL
  10625. return __this_cpu_read(__kmap_atomic_idx) - 1;
  10626. +#else
  10627. + return current->kmap_idx - 1;
  10628. +#endif
  10629. }
  10630. static inline void kmap_atomic_idx_pop(void)
  10631. {
  10632. -#ifdef CONFIG_DEBUG_HIGHMEM
  10633. +#ifndef CONFIG_PREEMPT_RT_FULL
  10634. +# ifdef CONFIG_DEBUG_HIGHMEM
  10635. int idx = __this_cpu_dec_return(__kmap_atomic_idx);
  10636. BUG_ON(idx < 0);
  10637. -#else
  10638. +# else
  10639. __this_cpu_dec(__kmap_atomic_idx);
  10640. +# endif
  10641. +#else
  10642. + current->kmap_idx--;
  10643. +# ifdef CONFIG_DEBUG_HIGHMEM
  10644. + BUG_ON(current->kmap_idx < 0);
  10645. +# endif
  10646. #endif
  10647. }
  10648. diff -Nur linux-4.4.13.orig/include/linux/hrtimer.h linux-4.4.13/include/linux/hrtimer.h
  10649. --- linux-4.4.13.orig/include/linux/hrtimer.h 2016-06-08 03:14:51.000000000 +0200
  10650. +++ linux-4.4.13/include/linux/hrtimer.h 2016-06-22 21:55:08.030523867 +0200
  10651. @@ -87,6 +87,9 @@
  10652. * @function: timer expiry callback function
  10653. * @base: pointer to the timer base (per cpu and per clock)
  10654. * @state: state information (See bit values above)
  10655. + * @cb_entry: list entry to defer timers from hardirq context
  10656. + * @irqsafe: timer can run in hardirq context
  10657. + * @praecox: timer expiry time if expired at the time of programming
  10658. * @is_rel: Set if the timer was armed relative
  10659. * @start_pid: timer statistics field to store the pid of the task which
  10660. * started the timer
  10661. @@ -103,6 +106,11 @@
  10662. enum hrtimer_restart (*function)(struct hrtimer *);
  10663. struct hrtimer_clock_base *base;
  10664. u8 state;
  10665. + struct list_head cb_entry;
  10666. + int irqsafe;
  10667. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  10668. + ktime_t praecox;
  10669. +#endif
  10670. u8 is_rel;
  10671. #ifdef CONFIG_TIMER_STATS
  10672. int start_pid;
  10673. @@ -123,11 +131,7 @@
  10674. struct task_struct *task;
  10675. };
  10676. -#ifdef CONFIG_64BIT
  10677. # define HRTIMER_CLOCK_BASE_ALIGN 64
  10678. -#else
  10679. -# define HRTIMER_CLOCK_BASE_ALIGN 32
  10680. -#endif
  10681. /**
  10682. * struct hrtimer_clock_base - the timer base for a specific clock
  10683. @@ -136,6 +140,7 @@
  10684. * timer to a base on another cpu.
  10685. * @clockid: clock id for per_cpu support
  10686. * @active: red black tree root node for the active timers
  10687. + * @expired: list head for deferred timers.
  10688. * @get_time: function to retrieve the current time of the clock
  10689. * @offset: offset of this clock to the monotonic base
  10690. */
  10691. @@ -144,6 +149,7 @@
  10692. int index;
  10693. clockid_t clockid;
  10694. struct timerqueue_head active;
  10695. + struct list_head expired;
  10696. ktime_t (*get_time)(void);
  10697. ktime_t offset;
  10698. } __attribute__((__aligned__(HRTIMER_CLOCK_BASE_ALIGN)));
  10699. @@ -187,6 +193,7 @@
  10700. raw_spinlock_t lock;
  10701. seqcount_t seq;
  10702. struct hrtimer *running;
  10703. + struct hrtimer *running_soft;
  10704. unsigned int cpu;
  10705. unsigned int active_bases;
  10706. unsigned int clock_was_set_seq;
  10707. @@ -203,6 +210,9 @@
  10708. unsigned int nr_hangs;
  10709. unsigned int max_hang_time;
  10710. #endif
  10711. +#ifdef CONFIG_PREEMPT_RT_BASE
  10712. + wait_queue_head_t wait;
  10713. +#endif
  10714. struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];
  10715. } ____cacheline_aligned;
  10716. @@ -412,6 +422,13 @@
  10717. hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
  10718. }
  10719. +/* Softirq preemption could deadlock timer removal */
  10720. +#ifdef CONFIG_PREEMPT_RT_BASE
  10721. + extern void hrtimer_wait_for_timer(const struct hrtimer *timer);
  10722. +#else
  10723. +# define hrtimer_wait_for_timer(timer) do { cpu_relax(); } while (0)
  10724. +#endif
  10725. +
  10726. /* Query timers: */
  10727. extern ktime_t __hrtimer_get_remaining(const struct hrtimer *timer, bool adjust);
  10728. @@ -436,7 +453,7 @@
  10729. * Helper function to check, whether the timer is running the callback
  10730. * function
  10731. */
  10732. -static inline int hrtimer_callback_running(struct hrtimer *timer)
  10733. +static inline int hrtimer_callback_running(const struct hrtimer *timer)
  10734. {
  10735. return timer->base->cpu_base->running == timer;
  10736. }
  10737. diff -Nur linux-4.4.13.orig/include/linux/idr.h linux-4.4.13/include/linux/idr.h
  10738. --- linux-4.4.13.orig/include/linux/idr.h 2016-06-08 03:14:51.000000000 +0200
  10739. +++ linux-4.4.13/include/linux/idr.h 2016-06-22 21:55:08.030523867 +0200
  10740. @@ -95,10 +95,14 @@
  10741. * Each idr_preload() should be matched with an invocation of this
  10742. * function. See idr_preload() for details.
  10743. */
  10744. +#ifdef CONFIG_PREEMPT_RT_FULL
  10745. +void idr_preload_end(void);
  10746. +#else
  10747. static inline void idr_preload_end(void)
  10748. {
  10749. preempt_enable();
  10750. }
  10751. +#endif
  10752. /**
  10753. * idr_find - return pointer for given id
  10754. diff -Nur linux-4.4.13.orig/include/linux/init_task.h linux-4.4.13/include/linux/init_task.h
  10755. --- linux-4.4.13.orig/include/linux/init_task.h 2016-06-08 03:14:51.000000000 +0200
  10756. +++ linux-4.4.13/include/linux/init_task.h 2016-06-22 21:55:08.030523867 +0200
  10757. @@ -148,9 +148,15 @@
  10758. # define INIT_PERF_EVENTS(tsk)
  10759. #endif
  10760. +#ifdef CONFIG_PREEMPT_RT_BASE
  10761. +# define INIT_TIMER_LIST .posix_timer_list = NULL,
  10762. +#else
  10763. +# define INIT_TIMER_LIST
  10764. +#endif
  10765. +
  10766. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  10767. # define INIT_VTIME(tsk) \
  10768. - .vtime_seqlock = __SEQLOCK_UNLOCKED(tsk.vtime_seqlock), \
  10769. + .vtime_seqcount = SEQCNT_ZERO(tsk.vtime_seqcount), \
  10770. .vtime_snap = 0, \
  10771. .vtime_snap_whence = VTIME_SYS,
  10772. #else
  10773. @@ -239,6 +245,7 @@
  10774. .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
  10775. .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
  10776. .timer_slack_ns = 50000, /* 50 usec default slack */ \
  10777. + INIT_TIMER_LIST \
  10778. .pids = { \
  10779. [PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \
  10780. [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID), \
  10781. diff -Nur linux-4.4.13.orig/include/linux/interrupt.h linux-4.4.13/include/linux/interrupt.h
  10782. --- linux-4.4.13.orig/include/linux/interrupt.h 2016-06-08 03:14:51.000000000 +0200
  10783. +++ linux-4.4.13/include/linux/interrupt.h 2016-06-22 21:55:08.030523867 +0200
  10784. @@ -61,6 +61,7 @@
  10785. * interrupt handler after suspending interrupts. For system
  10786. * wakeup devices users need to implement wakeup detection in
  10787. * their interrupt handlers.
  10788. + * IRQF_NO_SOFTIRQ_CALL - Do not process softirqs in the irq thread context (RT)
  10789. */
  10790. #define IRQF_SHARED 0x00000080
  10791. #define IRQF_PROBE_SHARED 0x00000100
  10792. @@ -74,6 +75,7 @@
  10793. #define IRQF_NO_THREAD 0x00010000
  10794. #define IRQF_EARLY_RESUME 0x00020000
  10795. #define IRQF_COND_SUSPEND 0x00040000
  10796. +#define IRQF_NO_SOFTIRQ_CALL 0x00080000
  10797. #define IRQF_TIMER (__IRQF_TIMER | IRQF_NO_SUSPEND | IRQF_NO_THREAD)
  10798. @@ -186,7 +188,7 @@
  10799. #ifdef CONFIG_LOCKDEP
  10800. # define local_irq_enable_in_hardirq() do { } while (0)
  10801. #else
  10802. -# define local_irq_enable_in_hardirq() local_irq_enable()
  10803. +# define local_irq_enable_in_hardirq() local_irq_enable_nort()
  10804. #endif
  10805. extern void disable_irq_nosync(unsigned int irq);
  10806. @@ -206,6 +208,7 @@
  10807. * @irq: Interrupt to which notification applies
  10808. * @kref: Reference count, for internal use
  10809. * @work: Work item, for internal use
  10810. + * @list: List item for deferred callbacks
  10811. * @notify: Function to be called on change. This will be
  10812. * called in process context.
  10813. * @release: Function to be called on release. This will be
  10814. @@ -217,6 +220,7 @@
  10815. unsigned int irq;
  10816. struct kref kref;
  10817. struct work_struct work;
  10818. + struct list_head list;
  10819. void (*notify)(struct irq_affinity_notify *, const cpumask_t *mask);
  10820. void (*release)(struct kref *ref);
  10821. };
  10822. @@ -379,9 +383,13 @@
  10823. bool state);
  10824. #ifdef CONFIG_IRQ_FORCED_THREADING
  10825. +# ifndef CONFIG_PREEMPT_RT_BASE
  10826. extern bool force_irqthreads;
  10827. +# else
  10828. +# define force_irqthreads (true)
  10829. +# endif
  10830. #else
  10831. -#define force_irqthreads (0)
  10832. +#define force_irqthreads (false)
  10833. #endif
  10834. #ifndef __ARCH_SET_SOFTIRQ_PENDING
  10835. @@ -438,9 +446,10 @@
  10836. void (*action)(struct softirq_action *);
  10837. };
  10838. +#ifndef CONFIG_PREEMPT_RT_FULL
  10839. asmlinkage void do_softirq(void);
  10840. asmlinkage void __do_softirq(void);
  10841. -
  10842. +static inline void thread_do_softirq(void) { do_softirq(); }
  10843. #ifdef __ARCH_HAS_DO_SOFTIRQ
  10844. void do_softirq_own_stack(void);
  10845. #else
  10846. @@ -449,13 +458,25 @@
  10847. __do_softirq();
  10848. }
  10849. #endif
  10850. +#else
  10851. +extern void thread_do_softirq(void);
  10852. +#endif
  10853. extern void open_softirq(int nr, void (*action)(struct softirq_action *));
  10854. extern void softirq_init(void);
  10855. extern void __raise_softirq_irqoff(unsigned int nr);
  10856. +#ifdef CONFIG_PREEMPT_RT_FULL
  10857. +extern void __raise_softirq_irqoff_ksoft(unsigned int nr);
  10858. +#else
  10859. +static inline void __raise_softirq_irqoff_ksoft(unsigned int nr)
  10860. +{
  10861. + __raise_softirq_irqoff(nr);
  10862. +}
  10863. +#endif
  10864. extern void raise_softirq_irqoff(unsigned int nr);
  10865. extern void raise_softirq(unsigned int nr);
  10866. +extern void softirq_check_pending_idle(void);
  10867. DECLARE_PER_CPU(struct task_struct *, ksoftirqd);
  10868. @@ -477,8 +498,9 @@
  10869. to be executed on some cpu at least once after this.
  10870. * If the tasklet is already scheduled, but its execution is still not
  10871. started, it will be executed only once.
  10872. - * If this tasklet is already running on another CPU (or schedule is called
  10873. - from tasklet itself), it is rescheduled for later.
  10874. + * If this tasklet is already running on another CPU, it is rescheduled
  10875. + for later.
  10876. + * Schedule must not be called from the tasklet itself (a lockup occurs)
  10877. * Tasklet is strictly serialized wrt itself, but not
  10878. wrt another tasklets. If client needs some intertask synchronization,
  10879. he makes it with spinlocks.
  10880. @@ -503,27 +525,36 @@
  10881. enum
  10882. {
  10883. TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */
  10884. - TASKLET_STATE_RUN /* Tasklet is running (SMP only) */
  10885. + TASKLET_STATE_RUN, /* Tasklet is running (SMP only) */
  10886. + TASKLET_STATE_PENDING /* Tasklet is pending */
  10887. };
  10888. -#ifdef CONFIG_SMP
  10889. +#define TASKLET_STATEF_SCHED (1 << TASKLET_STATE_SCHED)
  10890. +#define TASKLET_STATEF_RUN (1 << TASKLET_STATE_RUN)
  10891. +#define TASKLET_STATEF_PENDING (1 << TASKLET_STATE_PENDING)
  10892. +
  10893. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  10894. static inline int tasklet_trylock(struct tasklet_struct *t)
  10895. {
  10896. return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
  10897. }
  10898. +static inline int tasklet_tryunlock(struct tasklet_struct *t)
  10899. +{
  10900. + return cmpxchg(&t->state, TASKLET_STATEF_RUN, 0) == TASKLET_STATEF_RUN;
  10901. +}
  10902. +
  10903. static inline void tasklet_unlock(struct tasklet_struct *t)
  10904. {
  10905. smp_mb__before_atomic();
  10906. clear_bit(TASKLET_STATE_RUN, &(t)->state);
  10907. }
  10908. -static inline void tasklet_unlock_wait(struct tasklet_struct *t)
  10909. -{
  10910. - while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
  10911. -}
  10912. +extern void tasklet_unlock_wait(struct tasklet_struct *t);
  10913. +
  10914. #else
  10915. #define tasklet_trylock(t) 1
  10916. +#define tasklet_tryunlock(t) 1
  10917. #define tasklet_unlock_wait(t) do { } while (0)
  10918. #define tasklet_unlock(t) do { } while (0)
  10919. #endif
  10920. @@ -572,12 +603,7 @@
  10921. smp_mb();
  10922. }
  10923. -static inline void tasklet_enable(struct tasklet_struct *t)
  10924. -{
  10925. - smp_mb__before_atomic();
  10926. - atomic_dec(&t->count);
  10927. -}
  10928. -
  10929. +extern void tasklet_enable(struct tasklet_struct *t);
  10930. extern void tasklet_kill(struct tasklet_struct *t);
  10931. extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
  10932. extern void tasklet_init(struct tasklet_struct *t,
  10933. @@ -608,6 +634,12 @@
  10934. tasklet_kill(&ttimer->tasklet);
  10935. }
  10936. +#ifdef CONFIG_PREEMPT_RT_FULL
  10937. +extern void softirq_early_init(void);
  10938. +#else
  10939. +static inline void softirq_early_init(void) { }
  10940. +#endif
  10941. +
  10942. /*
  10943. * Autoprobing for irqs:
  10944. *
  10945. diff -Nur linux-4.4.13.orig/include/linux/irqdesc.h linux-4.4.13/include/linux/irqdesc.h
  10946. --- linux-4.4.13.orig/include/linux/irqdesc.h 2016-06-08 03:14:51.000000000 +0200
  10947. +++ linux-4.4.13/include/linux/irqdesc.h 2016-06-22 21:55:08.030523867 +0200
  10948. @@ -61,6 +61,7 @@
  10949. unsigned int irqs_unhandled;
  10950. atomic_t threads_handled;
  10951. int threads_handled_last;
  10952. + u64 random_ip;
  10953. raw_spinlock_t lock;
  10954. struct cpumask *percpu_enabled;
  10955. #ifdef CONFIG_SMP
  10956. diff -Nur linux-4.4.13.orig/include/linux/irqflags.h linux-4.4.13/include/linux/irqflags.h
  10957. --- linux-4.4.13.orig/include/linux/irqflags.h 2016-06-08 03:14:51.000000000 +0200
  10958. +++ linux-4.4.13/include/linux/irqflags.h 2016-06-22 21:55:08.030523867 +0200
  10959. @@ -25,8 +25,6 @@
  10960. # define trace_softirqs_enabled(p) ((p)->softirqs_enabled)
  10961. # define trace_hardirq_enter() do { current->hardirq_context++; } while (0)
  10962. # define trace_hardirq_exit() do { current->hardirq_context--; } while (0)
  10963. -# define lockdep_softirq_enter() do { current->softirq_context++; } while (0)
  10964. -# define lockdep_softirq_exit() do { current->softirq_context--; } while (0)
  10965. # define INIT_TRACE_IRQFLAGS .softirqs_enabled = 1,
  10966. #else
  10967. # define trace_hardirqs_on() do { } while (0)
  10968. @@ -39,9 +37,15 @@
  10969. # define trace_softirqs_enabled(p) 0
  10970. # define trace_hardirq_enter() do { } while (0)
  10971. # define trace_hardirq_exit() do { } while (0)
  10972. +# define INIT_TRACE_IRQFLAGS
  10973. +#endif
  10974. +
  10975. +#if defined(CONFIG_TRACE_IRQFLAGS) && !defined(CONFIG_PREEMPT_RT_FULL)
  10976. +# define lockdep_softirq_enter() do { current->softirq_context++; } while (0)
  10977. +# define lockdep_softirq_exit() do { current->softirq_context--; } while (0)
  10978. +#else
  10979. # define lockdep_softirq_enter() do { } while (0)
  10980. # define lockdep_softirq_exit() do { } while (0)
  10981. -# define INIT_TRACE_IRQFLAGS
  10982. #endif
  10983. #if defined(CONFIG_IRQSOFF_TRACER) || \
  10984. @@ -148,4 +152,23 @@
  10985. #define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags)
  10986. +/*
  10987. + * local_irq* variants depending on RT/!RT
  10988. + */
  10989. +#ifdef CONFIG_PREEMPT_RT_FULL
  10990. +# define local_irq_disable_nort() do { } while (0)
  10991. +# define local_irq_enable_nort() do { } while (0)
  10992. +# define local_irq_save_nort(flags) local_save_flags(flags)
  10993. +# define local_irq_restore_nort(flags) (void)(flags)
  10994. +# define local_irq_disable_rt() local_irq_disable()
  10995. +# define local_irq_enable_rt() local_irq_enable()
  10996. +#else
  10997. +# define local_irq_disable_nort() local_irq_disable()
  10998. +# define local_irq_enable_nort() local_irq_enable()
  10999. +# define local_irq_save_nort(flags) local_irq_save(flags)
  11000. +# define local_irq_restore_nort(flags) local_irq_restore(flags)
  11001. +# define local_irq_disable_rt() do { } while (0)
  11002. +# define local_irq_enable_rt() do { } while (0)
  11003. +#endif
  11004. +
  11005. #endif
  11006. diff -Nur linux-4.4.13.orig/include/linux/irq.h linux-4.4.13/include/linux/irq.h
  11007. --- linux-4.4.13.orig/include/linux/irq.h 2016-06-08 03:14:51.000000000 +0200
  11008. +++ linux-4.4.13/include/linux/irq.h 2016-06-22 21:55:08.030523867 +0200
  11009. @@ -72,6 +72,7 @@
  11010. * IRQ_IS_POLLED - Always polled by another interrupt. Exclude
  11011. * it from the spurious interrupt detection
  11012. * mechanism and from core side polling.
  11013. + * IRQ_NO_SOFTIRQ_CALL - No softirq processing in the irq thread context (RT)
  11014. * IRQ_DISABLE_UNLAZY - Disable lazy irq disable
  11015. */
  11016. enum {
  11017. @@ -99,13 +100,14 @@
  11018. IRQ_PER_CPU_DEVID = (1 << 17),
  11019. IRQ_IS_POLLED = (1 << 18),
  11020. IRQ_DISABLE_UNLAZY = (1 << 19),
  11021. + IRQ_NO_SOFTIRQ_CALL = (1 << 20),
  11022. };
  11023. #define IRQF_MODIFY_MASK \
  11024. (IRQ_TYPE_SENSE_MASK | IRQ_NOPROBE | IRQ_NOREQUEST | \
  11025. IRQ_NOAUTOEN | IRQ_MOVE_PCNTXT | IRQ_LEVEL | IRQ_NO_BALANCING | \
  11026. IRQ_PER_CPU | IRQ_NESTED_THREAD | IRQ_NOTHREAD | IRQ_PER_CPU_DEVID | \
  11027. - IRQ_IS_POLLED | IRQ_DISABLE_UNLAZY)
  11028. + IRQ_IS_POLLED | IRQ_DISABLE_UNLAZY | IRQ_NO_SOFTIRQ_CALL)
  11029. #define IRQ_NO_BALANCING_MASK (IRQ_PER_CPU | IRQ_NO_BALANCING)
  11030. diff -Nur linux-4.4.13.orig/include/linux/irq_work.h linux-4.4.13/include/linux/irq_work.h
  11031. --- linux-4.4.13.orig/include/linux/irq_work.h 2016-06-08 03:14:51.000000000 +0200
  11032. +++ linux-4.4.13/include/linux/irq_work.h 2016-06-22 21:55:08.030523867 +0200
  11033. @@ -16,6 +16,7 @@
  11034. #define IRQ_WORK_BUSY 2UL
  11035. #define IRQ_WORK_FLAGS 3UL
  11036. #define IRQ_WORK_LAZY 4UL /* Doesn't want IPI, wait for tick */
  11037. +#define IRQ_WORK_HARD_IRQ 8UL /* Run hard IRQ context, even on RT */
  11038. struct irq_work {
  11039. unsigned long flags;
  11040. @@ -51,4 +52,10 @@
  11041. static inline void irq_work_run(void) { }
  11042. #endif
  11043. +#if defined(CONFIG_IRQ_WORK) && defined(CONFIG_PREEMPT_RT_FULL)
  11044. +void irq_work_tick_soft(void);
  11045. +#else
  11046. +static inline void irq_work_tick_soft(void) { }
  11047. +#endif
  11048. +
  11049. #endif /* _LINUX_IRQ_WORK_H */
  11050. diff -Nur linux-4.4.13.orig/include/linux/jbd2.h linux-4.4.13/include/linux/jbd2.h
  11051. --- linux-4.4.13.orig/include/linux/jbd2.h 2016-06-08 03:14:51.000000000 +0200
  11052. +++ linux-4.4.13/include/linux/jbd2.h 2016-06-22 21:55:08.030523867 +0200
  11053. @@ -352,32 +352,56 @@
  11054. static inline void jbd_lock_bh_state(struct buffer_head *bh)
  11055. {
  11056. +#ifndef CONFIG_PREEMPT_RT_BASE
  11057. bit_spin_lock(BH_State, &bh->b_state);
  11058. +#else
  11059. + spin_lock(&bh->b_state_lock);
  11060. +#endif
  11061. }
  11062. static inline int jbd_trylock_bh_state(struct buffer_head *bh)
  11063. {
  11064. +#ifndef CONFIG_PREEMPT_RT_BASE
  11065. return bit_spin_trylock(BH_State, &bh->b_state);
  11066. +#else
  11067. + return spin_trylock(&bh->b_state_lock);
  11068. +#endif
  11069. }
  11070. static inline int jbd_is_locked_bh_state(struct buffer_head *bh)
  11071. {
  11072. +#ifndef CONFIG_PREEMPT_RT_BASE
  11073. return bit_spin_is_locked(BH_State, &bh->b_state);
  11074. +#else
  11075. + return spin_is_locked(&bh->b_state_lock);
  11076. +#endif
  11077. }
  11078. static inline void jbd_unlock_bh_state(struct buffer_head *bh)
  11079. {
  11080. +#ifndef CONFIG_PREEMPT_RT_BASE
  11081. bit_spin_unlock(BH_State, &bh->b_state);
  11082. +#else
  11083. + spin_unlock(&bh->b_state_lock);
  11084. +#endif
  11085. }
  11086. static inline void jbd_lock_bh_journal_head(struct buffer_head *bh)
  11087. {
  11088. +#ifndef CONFIG_PREEMPT_RT_BASE
  11089. bit_spin_lock(BH_JournalHead, &bh->b_state);
  11090. +#else
  11091. + spin_lock(&bh->b_journal_head_lock);
  11092. +#endif
  11093. }
  11094. static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
  11095. {
  11096. +#ifndef CONFIG_PREEMPT_RT_BASE
  11097. bit_spin_unlock(BH_JournalHead, &bh->b_state);
  11098. +#else
  11099. + spin_unlock(&bh->b_journal_head_lock);
  11100. +#endif
  11101. }
  11102. #define J_ASSERT(assert) BUG_ON(!(assert))
  11103. diff -Nur linux-4.4.13.orig/include/linux/kdb.h linux-4.4.13/include/linux/kdb.h
  11104. --- linux-4.4.13.orig/include/linux/kdb.h 2016-06-08 03:14:51.000000000 +0200
  11105. +++ linux-4.4.13/include/linux/kdb.h 2016-06-22 21:55:08.030523867 +0200
  11106. @@ -167,6 +167,7 @@
  11107. extern __printf(1, 2) int kdb_printf(const char *, ...);
  11108. typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
  11109. +#define in_kdb_printk() (kdb_trap_printk)
  11110. extern void kdb_init(int level);
  11111. /* Access to kdb specific polling devices */
  11112. @@ -201,6 +202,7 @@
  11113. extern int kdb_unregister(char *);
  11114. #else /* ! CONFIG_KGDB_KDB */
  11115. static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
  11116. +#define in_kdb_printk() (0)
  11117. static inline void kdb_init(int level) {}
  11118. static inline int kdb_register(char *cmd, kdb_func_t func, char *usage,
  11119. char *help, short minlen) { return 0; }
  11120. diff -Nur linux-4.4.13.orig/include/linux/kernel.h linux-4.4.13/include/linux/kernel.h
  11121. --- linux-4.4.13.orig/include/linux/kernel.h 2016-06-08 03:14:51.000000000 +0200
  11122. +++ linux-4.4.13/include/linux/kernel.h 2016-06-22 21:55:08.030523867 +0200
  11123. @@ -188,6 +188,9 @@
  11124. */
  11125. # define might_sleep() \
  11126. do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
  11127. +
  11128. +# define might_sleep_no_state_check() \
  11129. + do { ___might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
  11130. # define sched_annotate_sleep() (current->task_state_change = 0)
  11131. #else
  11132. static inline void ___might_sleep(const char *file, int line,
  11133. @@ -195,6 +198,7 @@
  11134. static inline void __might_sleep(const char *file, int line,
  11135. int preempt_offset) { }
  11136. # define might_sleep() do { might_resched(); } while (0)
  11137. +# define might_sleep_no_state_check() do { might_resched(); } while (0)
  11138. # define sched_annotate_sleep() do { } while (0)
  11139. #endif
  11140. @@ -255,6 +259,7 @@
  11141. __printf(1, 2)
  11142. void panic(const char *fmt, ...)
  11143. __noreturn __cold;
  11144. +void nmi_panic(struct pt_regs *regs, const char *msg);
  11145. extern void oops_enter(void);
  11146. extern void oops_exit(void);
  11147. void print_oops_end_marker(void);
  11148. @@ -446,6 +451,14 @@
  11149. extern bool crash_kexec_post_notifiers;
  11150. /*
  11151. + * panic_cpu is used for synchronizing panic() and crash_kexec() execution. It
  11152. + * holds a CPU number which is executing panic() currently. A value of
  11153. + * PANIC_CPU_INVALID means no CPU has entered panic() or crash_kexec().
  11154. + */
  11155. +extern atomic_t panic_cpu;
  11156. +#define PANIC_CPU_INVALID -1
  11157. +
  11158. +/*
  11159. * Only to be used by arch init code. If the user over-wrote the default
  11160. * CONFIG_PANIC_TIMEOUT, honor it.
  11161. */
  11162. @@ -473,6 +486,7 @@
  11163. SYSTEM_HALT,
  11164. SYSTEM_POWER_OFF,
  11165. SYSTEM_RESTART,
  11166. + SYSTEM_SUSPEND,
  11167. } system_state;
  11168. #define TAINT_PROPRIETARY_MODULE 0
  11169. diff -Nur linux-4.4.13.orig/include/linux/kvm_host.h linux-4.4.13/include/linux/kvm_host.h
  11170. --- linux-4.4.13.orig/include/linux/kvm_host.h 2016-06-08 03:14:51.000000000 +0200
  11171. +++ linux-4.4.13/include/linux/kvm_host.h 2016-06-22 21:55:08.030523867 +0200
  11172. @@ -25,6 +25,7 @@
  11173. #include <linux/irqflags.h>
  11174. #include <linux/context_tracking.h>
  11175. #include <linux/irqbypass.h>
  11176. +#include <linux/swait.h>
  11177. #include <asm/signal.h>
  11178. #include <linux/kvm.h>
  11179. @@ -243,7 +244,7 @@
  11180. int fpu_active;
  11181. int guest_fpu_loaded, guest_xcr0_loaded;
  11182. unsigned char fpu_counter;
  11183. - wait_queue_head_t wq;
  11184. + struct swait_queue_head wq;
  11185. struct pid *pid;
  11186. int sigset_active;
  11187. sigset_t sigset;
  11188. @@ -794,7 +795,7 @@
  11189. }
  11190. #endif
  11191. -static inline wait_queue_head_t *kvm_arch_vcpu_wq(struct kvm_vcpu *vcpu)
  11192. +static inline struct swait_queue_head *kvm_arch_vcpu_wq(struct kvm_vcpu *vcpu)
  11193. {
  11194. #ifdef __KVM_HAVE_ARCH_WQP
  11195. return vcpu->arch.wqp;
  11196. diff -Nur linux-4.4.13.orig/include/linux/lglock.h linux-4.4.13/include/linux/lglock.h
  11197. --- linux-4.4.13.orig/include/linux/lglock.h 2016-06-08 03:14:51.000000000 +0200
  11198. +++ linux-4.4.13/include/linux/lglock.h 2016-06-22 21:55:08.030523867 +0200
  11199. @@ -34,13 +34,30 @@
  11200. #endif
  11201. struct lglock {
  11202. +#ifdef CONFIG_PREEMPT_RT_FULL
  11203. + struct rt_mutex __percpu *lock;
  11204. +#else
  11205. arch_spinlock_t __percpu *lock;
  11206. +#endif
  11207. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  11208. struct lock_class_key lock_key;
  11209. struct lockdep_map lock_dep_map;
  11210. #endif
  11211. };
  11212. +#ifdef CONFIG_PREEMPT_RT_FULL
  11213. +# define DEFINE_LGLOCK(name) \
  11214. + static DEFINE_PER_CPU(struct rt_mutex, name ## _lock) \
  11215. + = __RT_MUTEX_INITIALIZER( name ## _lock); \
  11216. + struct lglock name = { .lock = &name ## _lock }
  11217. +
  11218. +# define DEFINE_STATIC_LGLOCK(name) \
  11219. + static DEFINE_PER_CPU(struct rt_mutex, name ## _lock) \
  11220. + = __RT_MUTEX_INITIALIZER( name ## _lock); \
  11221. + static struct lglock name = { .lock = &name ## _lock }
  11222. +
  11223. +#else
  11224. +
  11225. #define DEFINE_LGLOCK(name) \
  11226. static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
  11227. = __ARCH_SPIN_LOCK_UNLOCKED; \
  11228. @@ -50,6 +67,7 @@
  11229. static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
  11230. = __ARCH_SPIN_LOCK_UNLOCKED; \
  11231. static struct lglock name = { .lock = &name ## _lock }
  11232. +#endif
  11233. void lg_lock_init(struct lglock *lg, char *name);
  11234. @@ -64,6 +82,12 @@
  11235. void lg_global_lock(struct lglock *lg);
  11236. void lg_global_unlock(struct lglock *lg);
  11237. +#ifndef CONFIG_PREEMPT_RT_FULL
  11238. +#define lg_global_trylock_relax(name) lg_global_lock(name)
  11239. +#else
  11240. +void lg_global_trylock_relax(struct lglock *lg);
  11241. +#endif
  11242. +
  11243. #else
  11244. /* When !CONFIG_SMP, map lglock to spinlock */
  11245. #define lglock spinlock
  11246. diff -Nur linux-4.4.13.orig/include/linux/list_bl.h linux-4.4.13/include/linux/list_bl.h
  11247. --- linux-4.4.13.orig/include/linux/list_bl.h 2016-06-08 03:14:51.000000000 +0200
  11248. +++ linux-4.4.13/include/linux/list_bl.h 2016-06-22 21:55:08.030523867 +0200
  11249. @@ -2,6 +2,7 @@
  11250. #define _LINUX_LIST_BL_H
  11251. #include <linux/list.h>
  11252. +#include <linux/spinlock.h>
  11253. #include <linux/bit_spinlock.h>
  11254. /*
  11255. @@ -32,13 +33,24 @@
  11256. struct hlist_bl_head {
  11257. struct hlist_bl_node *first;
  11258. +#ifdef CONFIG_PREEMPT_RT_BASE
  11259. + raw_spinlock_t lock;
  11260. +#endif
  11261. };
  11262. struct hlist_bl_node {
  11263. struct hlist_bl_node *next, **pprev;
  11264. };
  11265. -#define INIT_HLIST_BL_HEAD(ptr) \
  11266. - ((ptr)->first = NULL)
  11267. +
  11268. +#ifdef CONFIG_PREEMPT_RT_BASE
  11269. +#define INIT_HLIST_BL_HEAD(h) \
  11270. +do { \
  11271. + (h)->first = NULL; \
  11272. + raw_spin_lock_init(&(h)->lock); \
  11273. +} while (0)
  11274. +#else
  11275. +#define INIT_HLIST_BL_HEAD(h) (h)->first = NULL
  11276. +#endif
  11277. static inline void INIT_HLIST_BL_NODE(struct hlist_bl_node *h)
  11278. {
  11279. @@ -118,12 +130,26 @@
  11280. static inline void hlist_bl_lock(struct hlist_bl_head *b)
  11281. {
  11282. +#ifndef CONFIG_PREEMPT_RT_BASE
  11283. bit_spin_lock(0, (unsigned long *)b);
  11284. +#else
  11285. + raw_spin_lock(&b->lock);
  11286. +#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
  11287. + __set_bit(0, (unsigned long *)b);
  11288. +#endif
  11289. +#endif
  11290. }
  11291. static inline void hlist_bl_unlock(struct hlist_bl_head *b)
  11292. {
  11293. +#ifndef CONFIG_PREEMPT_RT_BASE
  11294. __bit_spin_unlock(0, (unsigned long *)b);
  11295. +#else
  11296. +#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
  11297. + __clear_bit(0, (unsigned long *)b);
  11298. +#endif
  11299. + raw_spin_unlock(&b->lock);
  11300. +#endif
  11301. }
  11302. static inline bool hlist_bl_is_locked(struct hlist_bl_head *b)
  11303. diff -Nur linux-4.4.13.orig/include/linux/locallock.h linux-4.4.13/include/linux/locallock.h
  11304. --- linux-4.4.13.orig/include/linux/locallock.h 1970-01-01 01:00:00.000000000 +0100
  11305. +++ linux-4.4.13/include/linux/locallock.h 2016-06-22 21:55:08.030523867 +0200
  11306. @@ -0,0 +1,270 @@
  11307. +#ifndef _LINUX_LOCALLOCK_H
  11308. +#define _LINUX_LOCALLOCK_H
  11309. +
  11310. +#include <linux/percpu.h>
  11311. +#include <linux/spinlock.h>
  11312. +
  11313. +#ifdef CONFIG_PREEMPT_RT_BASE
  11314. +
  11315. +#ifdef CONFIG_DEBUG_SPINLOCK
  11316. +# define LL_WARN(cond) WARN_ON(cond)
  11317. +#else
  11318. +# define LL_WARN(cond) do { } while (0)
  11319. +#endif
  11320. +
  11321. +/*
  11322. + * per cpu lock based substitute for local_irq_*()
  11323. + */
  11324. +struct local_irq_lock {
  11325. + spinlock_t lock;
  11326. + struct task_struct *owner;
  11327. + int nestcnt;
  11328. + unsigned long flags;
  11329. +};
  11330. +
  11331. +#define DEFINE_LOCAL_IRQ_LOCK(lvar) \
  11332. + DEFINE_PER_CPU(struct local_irq_lock, lvar) = { \
  11333. + .lock = __SPIN_LOCK_UNLOCKED((lvar).lock) }
  11334. +
  11335. +#define DECLARE_LOCAL_IRQ_LOCK(lvar) \
  11336. + DECLARE_PER_CPU(struct local_irq_lock, lvar)
  11337. +
  11338. +#define local_irq_lock_init(lvar) \
  11339. + do { \
  11340. + int __cpu; \
  11341. + for_each_possible_cpu(__cpu) \
  11342. + spin_lock_init(&per_cpu(lvar, __cpu).lock); \
  11343. + } while (0)
  11344. +
  11345. +/*
  11346. + * spin_lock|trylock|unlock_local flavour that does not migrate disable
  11347. + * used for __local_lock|trylock|unlock where get_local_var/put_local_var
  11348. + * already takes care of the migrate_disable/enable
  11349. + * for CONFIG_PREEMPT_BASE map to the normal spin_* calls.
  11350. + */
  11351. +#ifdef CONFIG_PREEMPT_RT_FULL
  11352. +# define spin_lock_local(lock) rt_spin_lock__no_mg(lock)
  11353. +# define spin_trylock_local(lock) rt_spin_trylock__no_mg(lock)
  11354. +# define spin_unlock_local(lock) rt_spin_unlock__no_mg(lock)
  11355. +#else
  11356. +# define spin_lock_local(lock) spin_lock(lock)
  11357. +# define spin_trylock_local(lock) spin_trylock(lock)
  11358. +# define spin_unlock_local(lock) spin_unlock(lock)
  11359. +#endif
  11360. +
  11361. +static inline void __local_lock(struct local_irq_lock *lv)
  11362. +{
  11363. + if (lv->owner != current) {
  11364. + spin_lock_local(&lv->lock);
  11365. + LL_WARN(lv->owner);
  11366. + LL_WARN(lv->nestcnt);
  11367. + lv->owner = current;
  11368. + }
  11369. + lv->nestcnt++;
  11370. +}
  11371. +
  11372. +#define local_lock(lvar) \
  11373. + do { __local_lock(&get_local_var(lvar)); } while (0)
  11374. +
  11375. +static inline int __local_trylock(struct local_irq_lock *lv)
  11376. +{
  11377. + if (lv->owner != current && spin_trylock_local(&lv->lock)) {
  11378. + LL_WARN(lv->owner);
  11379. + LL_WARN(lv->nestcnt);
  11380. + lv->owner = current;
  11381. + lv->nestcnt = 1;
  11382. + return 1;
  11383. + }
  11384. + return 0;
  11385. +}
  11386. +
  11387. +#define local_trylock(lvar) \
  11388. + ({ \
  11389. + int __locked; \
  11390. + __locked = __local_trylock(&get_local_var(lvar)); \
  11391. + if (!__locked) \
  11392. + put_local_var(lvar); \
  11393. + __locked; \
  11394. + })
  11395. +
  11396. +static inline void __local_unlock(struct local_irq_lock *lv)
  11397. +{
  11398. + LL_WARN(lv->nestcnt == 0);
  11399. + LL_WARN(lv->owner != current);
  11400. + if (--lv->nestcnt)
  11401. + return;
  11402. +
  11403. + lv->owner = NULL;
  11404. + spin_unlock_local(&lv->lock);
  11405. +}
  11406. +
  11407. +#define local_unlock(lvar) \
  11408. + do { \
  11409. + __local_unlock(this_cpu_ptr(&lvar)); \
  11410. + put_local_var(lvar); \
  11411. + } while (0)
  11412. +
  11413. +static inline void __local_lock_irq(struct local_irq_lock *lv)
  11414. +{
  11415. + spin_lock_irqsave(&lv->lock, lv->flags);
  11416. + LL_WARN(lv->owner);
  11417. + LL_WARN(lv->nestcnt);
  11418. + lv->owner = current;
  11419. + lv->nestcnt = 1;
  11420. +}
  11421. +
  11422. +#define local_lock_irq(lvar) \
  11423. + do { __local_lock_irq(&get_local_var(lvar)); } while (0)
  11424. +
  11425. +#define local_lock_irq_on(lvar, cpu) \
  11426. + do { __local_lock_irq(&per_cpu(lvar, cpu)); } while (0)
  11427. +
  11428. +static inline void __local_unlock_irq(struct local_irq_lock *lv)
  11429. +{
  11430. + LL_WARN(!lv->nestcnt);
  11431. + LL_WARN(lv->owner != current);
  11432. + lv->owner = NULL;
  11433. + lv->nestcnt = 0;
  11434. + spin_unlock_irq(&lv->lock);
  11435. +}
  11436. +
  11437. +#define local_unlock_irq(lvar) \
  11438. + do { \
  11439. + __local_unlock_irq(this_cpu_ptr(&lvar)); \
  11440. + put_local_var(lvar); \
  11441. + } while (0)
  11442. +
  11443. +#define local_unlock_irq_on(lvar, cpu) \
  11444. + do { \
  11445. + __local_unlock_irq(&per_cpu(lvar, cpu)); \
  11446. + } while (0)
  11447. +
  11448. +static inline int __local_lock_irqsave(struct local_irq_lock *lv)
  11449. +{
  11450. + if (lv->owner != current) {
  11451. + __local_lock_irq(lv);
  11452. + return 0;
  11453. + } else {
  11454. + lv->nestcnt++;
  11455. + return 1;
  11456. + }
  11457. +}
  11458. +
  11459. +#define local_lock_irqsave(lvar, _flags) \
  11460. + do { \
  11461. + if (__local_lock_irqsave(&get_local_var(lvar))) \
  11462. + put_local_var(lvar); \
  11463. + _flags = __this_cpu_read(lvar.flags); \
  11464. + } while (0)
  11465. +
  11466. +#define local_lock_irqsave_on(lvar, _flags, cpu) \
  11467. + do { \
  11468. + __local_lock_irqsave(&per_cpu(lvar, cpu)); \
  11469. + _flags = per_cpu(lvar, cpu).flags; \
  11470. + } while (0)
  11471. +
  11472. +static inline int __local_unlock_irqrestore(struct local_irq_lock *lv,
  11473. + unsigned long flags)
  11474. +{
  11475. + LL_WARN(!lv->nestcnt);
  11476. + LL_WARN(lv->owner != current);
  11477. + if (--lv->nestcnt)
  11478. + return 0;
  11479. +
  11480. + lv->owner = NULL;
  11481. + spin_unlock_irqrestore(&lv->lock, lv->flags);
  11482. + return 1;
  11483. +}
  11484. +
  11485. +#define local_unlock_irqrestore(lvar, flags) \
  11486. + do { \
  11487. + if (__local_unlock_irqrestore(this_cpu_ptr(&lvar), flags)) \
  11488. + put_local_var(lvar); \
  11489. + } while (0)
  11490. +
  11491. +#define local_unlock_irqrestore_on(lvar, flags, cpu) \
  11492. + do { \
  11493. + __local_unlock_irqrestore(&per_cpu(lvar, cpu), flags); \
  11494. + } while (0)
  11495. +
  11496. +#define local_spin_trylock_irq(lvar, lock) \
  11497. + ({ \
  11498. + int __locked; \
  11499. + local_lock_irq(lvar); \
  11500. + __locked = spin_trylock(lock); \
  11501. + if (!__locked) \
  11502. + local_unlock_irq(lvar); \
  11503. + __locked; \
  11504. + })
  11505. +
  11506. +#define local_spin_lock_irq(lvar, lock) \
  11507. + do { \
  11508. + local_lock_irq(lvar); \
  11509. + spin_lock(lock); \
  11510. + } while (0)
  11511. +
  11512. +#define local_spin_unlock_irq(lvar, lock) \
  11513. + do { \
  11514. + spin_unlock(lock); \
  11515. + local_unlock_irq(lvar); \
  11516. + } while (0)
  11517. +
  11518. +#define local_spin_lock_irqsave(lvar, lock, flags) \
  11519. + do { \
  11520. + local_lock_irqsave(lvar, flags); \
  11521. + spin_lock(lock); \
  11522. + } while (0)
  11523. +
  11524. +#define local_spin_unlock_irqrestore(lvar, lock, flags) \
  11525. + do { \
  11526. + spin_unlock(lock); \
  11527. + local_unlock_irqrestore(lvar, flags); \
  11528. + } while (0)
  11529. +
  11530. +#define get_locked_var(lvar, var) \
  11531. + (*({ \
  11532. + local_lock(lvar); \
  11533. + this_cpu_ptr(&var); \
  11534. + }))
  11535. +
  11536. +#define put_locked_var(lvar, var) local_unlock(lvar);
  11537. +
  11538. +#define local_lock_cpu(lvar) \
  11539. + ({ \
  11540. + local_lock(lvar); \
  11541. + smp_processor_id(); \
  11542. + })
  11543. +
  11544. +#define local_unlock_cpu(lvar) local_unlock(lvar)
  11545. +
  11546. +#else /* PREEMPT_RT_BASE */
  11547. +
  11548. +#define DEFINE_LOCAL_IRQ_LOCK(lvar) __typeof__(const int) lvar
  11549. +#define DECLARE_LOCAL_IRQ_LOCK(lvar) extern __typeof__(const int) lvar
  11550. +
  11551. +static inline void local_irq_lock_init(int lvar) { }
  11552. +
  11553. +#define local_lock(lvar) preempt_disable()
  11554. +#define local_unlock(lvar) preempt_enable()
  11555. +#define local_lock_irq(lvar) local_irq_disable()
  11556. +#define local_unlock_irq(lvar) local_irq_enable()
  11557. +#define local_lock_irqsave(lvar, flags) local_irq_save(flags)
  11558. +#define local_unlock_irqrestore(lvar, flags) local_irq_restore(flags)
  11559. +
  11560. +#define local_spin_trylock_irq(lvar, lock) spin_trylock_irq(lock)
  11561. +#define local_spin_lock_irq(lvar, lock) spin_lock_irq(lock)
  11562. +#define local_spin_unlock_irq(lvar, lock) spin_unlock_irq(lock)
  11563. +#define local_spin_lock_irqsave(lvar, lock, flags) \
  11564. + spin_lock_irqsave(lock, flags)
  11565. +#define local_spin_unlock_irqrestore(lvar, lock, flags) \
  11566. + spin_unlock_irqrestore(lock, flags)
  11567. +
  11568. +#define get_locked_var(lvar, var) get_cpu_var(var)
  11569. +#define put_locked_var(lvar, var) put_cpu_var(var)
  11570. +
  11571. +#define local_lock_cpu(lvar) get_cpu()
  11572. +#define local_unlock_cpu(lvar) put_cpu()
  11573. +
  11574. +#endif
  11575. +
  11576. +#endif
  11577. diff -Nur linux-4.4.13.orig/include/linux/mm_types.h linux-4.4.13/include/linux/mm_types.h
  11578. --- linux-4.4.13.orig/include/linux/mm_types.h 2016-06-08 03:14:51.000000000 +0200
  11579. +++ linux-4.4.13/include/linux/mm_types.h 2016-06-22 21:55:08.030523867 +0200
  11580. @@ -11,6 +11,7 @@
  11581. #include <linux/completion.h>
  11582. #include <linux/cpumask.h>
  11583. #include <linux/uprobes.h>
  11584. +#include <linux/rcupdate.h>
  11585. #include <linux/page-flags-layout.h>
  11586. #include <asm/page.h>
  11587. #include <asm/mmu.h>
  11588. @@ -504,6 +505,9 @@
  11589. bool tlb_flush_pending;
  11590. #endif
  11591. struct uprobes_state uprobes_state;
  11592. +#ifdef CONFIG_PREEMPT_RT_BASE
  11593. + struct rcu_head delayed_drop;
  11594. +#endif
  11595. #ifdef CONFIG_X86_INTEL_MPX
  11596. /* address of the bounds directory */
  11597. void __user *bd_addr;
  11598. diff -Nur linux-4.4.13.orig/include/linux/mutex.h linux-4.4.13/include/linux/mutex.h
  11599. --- linux-4.4.13.orig/include/linux/mutex.h 2016-06-08 03:14:51.000000000 +0200
  11600. +++ linux-4.4.13/include/linux/mutex.h 2016-06-22 21:55:08.034523867 +0200
  11601. @@ -19,6 +19,17 @@
  11602. #include <asm/processor.h>
  11603. #include <linux/osq_lock.h>
  11604. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11605. +# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
  11606. + , .dep_map = { .name = #lockname }
  11607. +#else
  11608. +# define __DEP_MAP_MUTEX_INITIALIZER(lockname)
  11609. +#endif
  11610. +
  11611. +#ifdef CONFIG_PREEMPT_RT_FULL
  11612. +# include <linux/mutex_rt.h>
  11613. +#else
  11614. +
  11615. /*
  11616. * Simple, straightforward mutexes with strict semantics:
  11617. *
  11618. @@ -99,13 +110,6 @@
  11619. static inline void mutex_destroy(struct mutex *lock) {}
  11620. #endif
  11621. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11622. -# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
  11623. - , .dep_map = { .name = #lockname }
  11624. -#else
  11625. -# define __DEP_MAP_MUTEX_INITIALIZER(lockname)
  11626. -#endif
  11627. -
  11628. #define __MUTEX_INITIALIZER(lockname) \
  11629. { .count = ATOMIC_INIT(1) \
  11630. , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
  11631. @@ -173,6 +177,8 @@
  11632. extern int mutex_trylock(struct mutex *lock);
  11633. extern void mutex_unlock(struct mutex *lock);
  11634. +#endif /* !PREEMPT_RT_FULL */
  11635. +
  11636. extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);
  11637. #endif /* __LINUX_MUTEX_H */
  11638. diff -Nur linux-4.4.13.orig/include/linux/mutex_rt.h linux-4.4.13/include/linux/mutex_rt.h
  11639. --- linux-4.4.13.orig/include/linux/mutex_rt.h 1970-01-01 01:00:00.000000000 +0100
  11640. +++ linux-4.4.13/include/linux/mutex_rt.h 2016-06-22 21:55:08.034523867 +0200
  11641. @@ -0,0 +1,84 @@
  11642. +#ifndef __LINUX_MUTEX_RT_H
  11643. +#define __LINUX_MUTEX_RT_H
  11644. +
  11645. +#ifndef __LINUX_MUTEX_H
  11646. +#error "Please include mutex.h"
  11647. +#endif
  11648. +
  11649. +#include <linux/rtmutex.h>
  11650. +
  11651. +/* FIXME: Just for __lockfunc */
  11652. +#include <linux/spinlock.h>
  11653. +
  11654. +struct mutex {
  11655. + struct rt_mutex lock;
  11656. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11657. + struct lockdep_map dep_map;
  11658. +#endif
  11659. +};
  11660. +
  11661. +#define __MUTEX_INITIALIZER(mutexname) \
  11662. + { \
  11663. + .lock = __RT_MUTEX_INITIALIZER(mutexname.lock) \
  11664. + __DEP_MAP_MUTEX_INITIALIZER(mutexname) \
  11665. + }
  11666. +
  11667. +#define DEFINE_MUTEX(mutexname) \
  11668. + struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
  11669. +
  11670. +extern void __mutex_do_init(struct mutex *lock, const char *name, struct lock_class_key *key);
  11671. +extern void __lockfunc _mutex_lock(struct mutex *lock);
  11672. +extern int __lockfunc _mutex_lock_interruptible(struct mutex *lock);
  11673. +extern int __lockfunc _mutex_lock_killable(struct mutex *lock);
  11674. +extern void __lockfunc _mutex_lock_nested(struct mutex *lock, int subclass);
  11675. +extern void __lockfunc _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest_lock);
  11676. +extern int __lockfunc _mutex_lock_interruptible_nested(struct mutex *lock, int subclass);
  11677. +extern int __lockfunc _mutex_lock_killable_nested(struct mutex *lock, int subclass);
  11678. +extern int __lockfunc _mutex_trylock(struct mutex *lock);
  11679. +extern void __lockfunc _mutex_unlock(struct mutex *lock);
  11680. +
  11681. +#define mutex_is_locked(l) rt_mutex_is_locked(&(l)->lock)
  11682. +#define mutex_lock(l) _mutex_lock(l)
  11683. +#define mutex_lock_interruptible(l) _mutex_lock_interruptible(l)
  11684. +#define mutex_lock_killable(l) _mutex_lock_killable(l)
  11685. +#define mutex_trylock(l) _mutex_trylock(l)
  11686. +#define mutex_unlock(l) _mutex_unlock(l)
  11687. +#define mutex_destroy(l) rt_mutex_destroy(&(l)->lock)
  11688. +
  11689. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11690. +# define mutex_lock_nested(l, s) _mutex_lock_nested(l, s)
  11691. +# define mutex_lock_interruptible_nested(l, s) \
  11692. + _mutex_lock_interruptible_nested(l, s)
  11693. +# define mutex_lock_killable_nested(l, s) \
  11694. + _mutex_lock_killable_nested(l, s)
  11695. +
  11696. +# define mutex_lock_nest_lock(lock, nest_lock) \
  11697. +do { \
  11698. + typecheck(struct lockdep_map *, &(nest_lock)->dep_map); \
  11699. + _mutex_lock_nest_lock(lock, &(nest_lock)->dep_map); \
  11700. +} while (0)
  11701. +
  11702. +#else
  11703. +# define mutex_lock_nested(l, s) _mutex_lock(l)
  11704. +# define mutex_lock_interruptible_nested(l, s) \
  11705. + _mutex_lock_interruptible(l)
  11706. +# define mutex_lock_killable_nested(l, s) \
  11707. + _mutex_lock_killable(l)
  11708. +# define mutex_lock_nest_lock(lock, nest_lock) mutex_lock(lock)
  11709. +#endif
  11710. +
  11711. +# define mutex_init(mutex) \
  11712. +do { \
  11713. + static struct lock_class_key __key; \
  11714. + \
  11715. + rt_mutex_init(&(mutex)->lock); \
  11716. + __mutex_do_init((mutex), #mutex, &__key); \
  11717. +} while (0)
  11718. +
  11719. +# define __mutex_init(mutex, name, key) \
  11720. +do { \
  11721. + rt_mutex_init(&(mutex)->lock); \
  11722. + __mutex_do_init((mutex), name, key); \
  11723. +} while (0)
  11724. +
  11725. +#endif
  11726. diff -Nur linux-4.4.13.orig/include/linux/netdevice.h linux-4.4.13/include/linux/netdevice.h
  11727. --- linux-4.4.13.orig/include/linux/netdevice.h 2016-06-08 03:14:51.000000000 +0200
  11728. +++ linux-4.4.13/include/linux/netdevice.h 2016-06-22 21:55:08.034523867 +0200
  11729. @@ -2249,11 +2249,20 @@
  11730. void synchronize_net(void);
  11731. int init_dummy_netdev(struct net_device *dev);
  11732. +#ifdef CONFIG_PREEMPT_RT_FULL
  11733. +static inline int dev_recursion_level(void)
  11734. +{
  11735. + return current->xmit_recursion;
  11736. +}
  11737. +
  11738. +#else
  11739. +
  11740. DECLARE_PER_CPU(int, xmit_recursion);
  11741. static inline int dev_recursion_level(void)
  11742. {
  11743. return this_cpu_read(xmit_recursion);
  11744. }
  11745. +#endif
  11746. struct net_device *dev_get_by_index(struct net *net, int ifindex);
  11747. struct net_device *__dev_get_by_index(struct net *net, int ifindex);
  11748. @@ -2564,6 +2573,7 @@
  11749. unsigned int dropped;
  11750. struct sk_buff_head input_pkt_queue;
  11751. struct napi_struct backlog;
  11752. + struct sk_buff_head tofree_queue;
  11753. };
  11754. diff -Nur linux-4.4.13.orig/include/linux/netfilter/x_tables.h linux-4.4.13/include/linux/netfilter/x_tables.h
  11755. --- linux-4.4.13.orig/include/linux/netfilter/x_tables.h 2016-06-08 03:14:51.000000000 +0200
  11756. +++ linux-4.4.13/include/linux/netfilter/x_tables.h 2016-06-22 21:55:08.034523867 +0200
  11757. @@ -4,6 +4,7 @@
  11758. #include <linux/netdevice.h>
  11759. #include <linux/static_key.h>
  11760. +#include <linux/locallock.h>
  11761. #include <uapi/linux/netfilter/x_tables.h>
  11762. /**
  11763. @@ -282,6 +283,8 @@
  11764. */
  11765. DECLARE_PER_CPU(seqcount_t, xt_recseq);
  11766. +DECLARE_LOCAL_IRQ_LOCK(xt_write_lock);
  11767. +
  11768. /* xt_tee_enabled - true if x_tables needs to handle reentrancy
  11769. *
  11770. * Enabled if current ip(6)tables ruleset has at least one -j TEE rule.
  11771. @@ -302,6 +305,9 @@
  11772. {
  11773. unsigned int addend;
  11774. + /* RT protection */
  11775. + local_lock(xt_write_lock);
  11776. +
  11777. /*
  11778. * Low order bit of sequence is set if we already
  11779. * called xt_write_recseq_begin().
  11780. @@ -332,6 +338,7 @@
  11781. /* this is kind of a write_seqcount_end(), but addend is 0 or 1 */
  11782. smp_wmb();
  11783. __this_cpu_add(xt_recseq.sequence, addend);
  11784. + local_unlock(xt_write_lock);
  11785. }
  11786. /*
  11787. diff -Nur linux-4.4.13.orig/include/linux/notifier.h linux-4.4.13/include/linux/notifier.h
  11788. --- linux-4.4.13.orig/include/linux/notifier.h 2016-06-08 03:14:51.000000000 +0200
  11789. +++ linux-4.4.13/include/linux/notifier.h 2016-06-22 21:55:08.034523867 +0200
  11790. @@ -6,7 +6,7 @@
  11791. *
  11792. * Alan Cox <Alan.Cox@linux.org>
  11793. */
  11794. -
  11795. +
  11796. #ifndef _LINUX_NOTIFIER_H
  11797. #define _LINUX_NOTIFIER_H
  11798. #include <linux/errno.h>
  11799. @@ -42,9 +42,7 @@
  11800. * in srcu_notifier_call_chain(): no cache bounces and no memory barriers.
  11801. * As compensation, srcu_notifier_chain_unregister() is rather expensive.
  11802. * SRCU notifier chains should be used when the chain will be called very
  11803. - * often but notifier_blocks will seldom be removed. Also, SRCU notifier
  11804. - * chains are slightly more difficult to use because they require special
  11805. - * runtime initialization.
  11806. + * often but notifier_blocks will seldom be removed.
  11807. */
  11808. typedef int (*notifier_fn_t)(struct notifier_block *nb,
  11809. @@ -88,7 +86,7 @@
  11810. (name)->head = NULL; \
  11811. } while (0)
  11812. -/* srcu_notifier_heads must be initialized and cleaned up dynamically */
  11813. +/* srcu_notifier_heads must be cleaned up dynamically */
  11814. extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
  11815. #define srcu_cleanup_notifier_head(name) \
  11816. cleanup_srcu_struct(&(name)->srcu);
  11817. @@ -101,7 +99,13 @@
  11818. .head = NULL }
  11819. #define RAW_NOTIFIER_INIT(name) { \
  11820. .head = NULL }
  11821. -/* srcu_notifier_heads cannot be initialized statically */
  11822. +
  11823. +#define SRCU_NOTIFIER_INIT(name, pcpu) \
  11824. + { \
  11825. + .mutex = __MUTEX_INITIALIZER(name.mutex), \
  11826. + .head = NULL, \
  11827. + .srcu = __SRCU_STRUCT_INIT(name.srcu, pcpu), \
  11828. + }
  11829. #define ATOMIC_NOTIFIER_HEAD(name) \
  11830. struct atomic_notifier_head name = \
  11831. @@ -113,6 +117,18 @@
  11832. struct raw_notifier_head name = \
  11833. RAW_NOTIFIER_INIT(name)
  11834. +#define _SRCU_NOTIFIER_HEAD(name, mod) \
  11835. + static DEFINE_PER_CPU(struct srcu_struct_array, \
  11836. + name##_head_srcu_array); \
  11837. + mod struct srcu_notifier_head name = \
  11838. + SRCU_NOTIFIER_INIT(name, name##_head_srcu_array)
  11839. +
  11840. +#define SRCU_NOTIFIER_HEAD(name) \
  11841. + _SRCU_NOTIFIER_HEAD(name, )
  11842. +
  11843. +#define SRCU_NOTIFIER_HEAD_STATIC(name) \
  11844. + _SRCU_NOTIFIER_HEAD(name, static)
  11845. +
  11846. #ifdef __KERNEL__
  11847. extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
  11848. @@ -182,12 +198,12 @@
  11849. /*
  11850. * Declared notifiers so far. I can imagine quite a few more chains
  11851. - * over time (eg laptop power reset chains, reboot chain (to clean
  11852. + * over time (eg laptop power reset chains, reboot chain (to clean
  11853. * device units up), device [un]mount chain, module load/unload chain,
  11854. - * low memory chain, screenblank chain (for plug in modular screenblankers)
  11855. + * low memory chain, screenblank chain (for plug in modular screenblankers)
  11856. * VC switch chains (for loadable kernel svgalib VC switch helpers) etc...
  11857. */
  11858. -
  11859. +
  11860. /* CPU notfiers are defined in include/linux/cpu.h. */
  11861. /* netdevice notifiers are defined in include/linux/netdevice.h */
  11862. diff -Nur linux-4.4.13.orig/include/linux/percpu.h linux-4.4.13/include/linux/percpu.h
  11863. --- linux-4.4.13.orig/include/linux/percpu.h 2016-06-08 03:14:51.000000000 +0200
  11864. +++ linux-4.4.13/include/linux/percpu.h 2016-06-22 21:55:08.034523867 +0200
  11865. @@ -24,6 +24,35 @@
  11866. PERCPU_MODULE_RESERVE)
  11867. #endif
  11868. +#ifdef CONFIG_PREEMPT_RT_FULL
  11869. +
  11870. +#define get_local_var(var) (*({ \
  11871. + migrate_disable(); \
  11872. + this_cpu_ptr(&var); }))
  11873. +
  11874. +#define put_local_var(var) do { \
  11875. + (void)&(var); \
  11876. + migrate_enable(); \
  11877. +} while (0)
  11878. +
  11879. +# define get_local_ptr(var) ({ \
  11880. + migrate_disable(); \
  11881. + this_cpu_ptr(var); })
  11882. +
  11883. +# define put_local_ptr(var) do { \
  11884. + (void)(var); \
  11885. + migrate_enable(); \
  11886. +} while (0)
  11887. +
  11888. +#else
  11889. +
  11890. +#define get_local_var(var) get_cpu_var(var)
  11891. +#define put_local_var(var) put_cpu_var(var)
  11892. +#define get_local_ptr(var) get_cpu_ptr(var)
  11893. +#define put_local_ptr(var) put_cpu_ptr(var)
  11894. +
  11895. +#endif
  11896. +
  11897. /* minimum unit size, also is the maximum supported allocation size */
  11898. #define PCPU_MIN_UNIT_SIZE PFN_ALIGN(32 << 10)
  11899. diff -Nur linux-4.4.13.orig/include/linux/pid.h linux-4.4.13/include/linux/pid.h
  11900. --- linux-4.4.13.orig/include/linux/pid.h 2016-06-08 03:14:51.000000000 +0200
  11901. +++ linux-4.4.13/include/linux/pid.h 2016-06-22 21:55:08.034523867 +0200
  11902. @@ -2,6 +2,7 @@
  11903. #define _LINUX_PID_H
  11904. #include <linux/rcupdate.h>
  11905. +#include <linux/atomic.h>
  11906. enum pid_type
  11907. {
  11908. diff -Nur linux-4.4.13.orig/include/linux/preempt.h linux-4.4.13/include/linux/preempt.h
  11909. --- linux-4.4.13.orig/include/linux/preempt.h 2016-06-08 03:14:51.000000000 +0200
  11910. +++ linux-4.4.13/include/linux/preempt.h 2016-06-22 21:55:08.034523867 +0200
  11911. @@ -50,7 +50,11 @@
  11912. #define HARDIRQ_OFFSET (1UL << HARDIRQ_SHIFT)
  11913. #define NMI_OFFSET (1UL << NMI_SHIFT)
  11914. -#define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET)
  11915. +#ifndef CONFIG_PREEMPT_RT_FULL
  11916. +# define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET)
  11917. +#else
  11918. +# define SOFTIRQ_DISABLE_OFFSET (0)
  11919. +#endif
  11920. /* We use the MSB mostly because its available */
  11921. #define PREEMPT_NEED_RESCHED 0x80000000
  11922. @@ -59,9 +63,15 @@
  11923. #include <asm/preempt.h>
  11924. #define hardirq_count() (preempt_count() & HARDIRQ_MASK)
  11925. -#define softirq_count() (preempt_count() & SOFTIRQ_MASK)
  11926. #define irq_count() (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK \
  11927. | NMI_MASK))
  11928. +#ifndef CONFIG_PREEMPT_RT_FULL
  11929. +# define softirq_count() (preempt_count() & SOFTIRQ_MASK)
  11930. +# define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET)
  11931. +#else
  11932. +# define softirq_count() (0UL)
  11933. +extern int in_serving_softirq(void);
  11934. +#endif
  11935. /*
  11936. * Are we doing bottom half or hardware interrupt processing?
  11937. @@ -72,7 +82,6 @@
  11938. #define in_irq() (hardirq_count())
  11939. #define in_softirq() (softirq_count())
  11940. #define in_interrupt() (irq_count())
  11941. -#define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET)
  11942. /*
  11943. * Are we in NMI context?
  11944. @@ -91,7 +100,11 @@
  11945. /*
  11946. * The preempt_count offset after spin_lock()
  11947. */
  11948. +#if !defined(CONFIG_PREEMPT_RT_FULL)
  11949. #define PREEMPT_LOCK_OFFSET PREEMPT_DISABLE_OFFSET
  11950. +#else
  11951. +#define PREEMPT_LOCK_OFFSET 0
  11952. +#endif
  11953. /*
  11954. * The preempt_count offset needed for things like:
  11955. @@ -140,6 +153,20 @@
  11956. #define preempt_count_inc() preempt_count_add(1)
  11957. #define preempt_count_dec() preempt_count_sub(1)
  11958. +#ifdef CONFIG_PREEMPT_LAZY
  11959. +#define add_preempt_lazy_count(val) do { preempt_lazy_count() += (val); } while (0)
  11960. +#define sub_preempt_lazy_count(val) do { preempt_lazy_count() -= (val); } while (0)
  11961. +#define inc_preempt_lazy_count() add_preempt_lazy_count(1)
  11962. +#define dec_preempt_lazy_count() sub_preempt_lazy_count(1)
  11963. +#define preempt_lazy_count() (current_thread_info()->preempt_lazy_count)
  11964. +#else
  11965. +#define add_preempt_lazy_count(val) do { } while (0)
  11966. +#define sub_preempt_lazy_count(val) do { } while (0)
  11967. +#define inc_preempt_lazy_count() do { } while (0)
  11968. +#define dec_preempt_lazy_count() do { } while (0)
  11969. +#define preempt_lazy_count() (0)
  11970. +#endif
  11971. +
  11972. #ifdef CONFIG_PREEMPT_COUNT
  11973. #define preempt_disable() \
  11974. @@ -148,13 +175,25 @@
  11975. barrier(); \
  11976. } while (0)
  11977. +#define preempt_lazy_disable() \
  11978. +do { \
  11979. + inc_preempt_lazy_count(); \
  11980. + barrier(); \
  11981. +} while (0)
  11982. +
  11983. #define sched_preempt_enable_no_resched() \
  11984. do { \
  11985. barrier(); \
  11986. preempt_count_dec(); \
  11987. } while (0)
  11988. -#define preempt_enable_no_resched() sched_preempt_enable_no_resched()
  11989. +#ifdef CONFIG_PREEMPT_RT_BASE
  11990. +# define preempt_enable_no_resched() sched_preempt_enable_no_resched()
  11991. +# define preempt_check_resched_rt() preempt_check_resched()
  11992. +#else
  11993. +# define preempt_enable_no_resched() preempt_enable()
  11994. +# define preempt_check_resched_rt() barrier();
  11995. +#endif
  11996. #define preemptible() (preempt_count() == 0 && !irqs_disabled())
  11997. @@ -179,6 +218,13 @@
  11998. __preempt_schedule(); \
  11999. } while (0)
  12000. +#define preempt_lazy_enable() \
  12001. +do { \
  12002. + dec_preempt_lazy_count(); \
  12003. + barrier(); \
  12004. + preempt_check_resched(); \
  12005. +} while (0)
  12006. +
  12007. #else /* !CONFIG_PREEMPT */
  12008. #define preempt_enable() \
  12009. do { \
  12010. @@ -224,6 +270,7 @@
  12011. #define preempt_disable_notrace() barrier()
  12012. #define preempt_enable_no_resched_notrace() barrier()
  12013. #define preempt_enable_notrace() barrier()
  12014. +#define preempt_check_resched_rt() barrier()
  12015. #define preemptible() 0
  12016. #endif /* CONFIG_PREEMPT_COUNT */
  12017. @@ -244,10 +291,31 @@
  12018. } while (0)
  12019. #define preempt_fold_need_resched() \
  12020. do { \
  12021. - if (tif_need_resched()) \
  12022. + if (tif_need_resched_now()) \
  12023. set_preempt_need_resched(); \
  12024. } while (0)
  12025. +#ifdef CONFIG_PREEMPT_RT_FULL
  12026. +# define preempt_disable_rt() preempt_disable()
  12027. +# define preempt_enable_rt() preempt_enable()
  12028. +# define preempt_disable_nort() barrier()
  12029. +# define preempt_enable_nort() barrier()
  12030. +# ifdef CONFIG_SMP
  12031. + extern void migrate_disable(void);
  12032. + extern void migrate_enable(void);
  12033. +# else /* CONFIG_SMP */
  12034. +# define migrate_disable() barrier()
  12035. +# define migrate_enable() barrier()
  12036. +# endif /* CONFIG_SMP */
  12037. +#else
  12038. +# define preempt_disable_rt() barrier()
  12039. +# define preempt_enable_rt() barrier()
  12040. +# define preempt_disable_nort() preempt_disable()
  12041. +# define preempt_enable_nort() preempt_enable()
  12042. +# define migrate_disable() preempt_disable()
  12043. +# define migrate_enable() preempt_enable()
  12044. +#endif
  12045. +
  12046. #ifdef CONFIG_PREEMPT_NOTIFIERS
  12047. struct preempt_notifier;
  12048. diff -Nur linux-4.4.13.orig/include/linux/printk.h linux-4.4.13/include/linux/printk.h
  12049. --- linux-4.4.13.orig/include/linux/printk.h 2016-06-08 03:14:51.000000000 +0200
  12050. +++ linux-4.4.13/include/linux/printk.h 2016-06-22 21:55:08.034523867 +0200
  12051. @@ -117,9 +117,11 @@
  12052. #ifdef CONFIG_EARLY_PRINTK
  12053. extern asmlinkage __printf(1, 2)
  12054. void early_printk(const char *fmt, ...);
  12055. +extern void printk_kill(void);
  12056. #else
  12057. static inline __printf(1, 2) __cold
  12058. void early_printk(const char *s, ...) { }
  12059. +static inline void printk_kill(void) { }
  12060. #endif
  12061. typedef __printf(1, 0) int (*printk_func_t)(const char *fmt, va_list args);
  12062. diff -Nur linux-4.4.13.orig/include/linux/radix-tree.h linux-4.4.13/include/linux/radix-tree.h
  12063. --- linux-4.4.13.orig/include/linux/radix-tree.h 2016-06-08 03:14:51.000000000 +0200
  12064. +++ linux-4.4.13/include/linux/radix-tree.h 2016-06-22 21:55:08.034523867 +0200
  12065. @@ -277,8 +277,13 @@
  12066. unsigned int radix_tree_gang_lookup_slot(struct radix_tree_root *root,
  12067. void ***results, unsigned long *indices,
  12068. unsigned long first_index, unsigned int max_items);
  12069. +#ifndef CONFIG_PREEMPT_RT_FULL
  12070. int radix_tree_preload(gfp_t gfp_mask);
  12071. int radix_tree_maybe_preload(gfp_t gfp_mask);
  12072. +#else
  12073. +static inline int radix_tree_preload(gfp_t gm) { return 0; }
  12074. +static inline int radix_tree_maybe_preload(gfp_t gfp_mask) { return 0; }
  12075. +#endif
  12076. void radix_tree_init(void);
  12077. void *radix_tree_tag_set(struct radix_tree_root *root,
  12078. unsigned long index, unsigned int tag);
  12079. @@ -303,7 +308,7 @@
  12080. static inline void radix_tree_preload_end(void)
  12081. {
  12082. - preempt_enable();
  12083. + preempt_enable_nort();
  12084. }
  12085. /**
  12086. diff -Nur linux-4.4.13.orig/include/linux/random.h linux-4.4.13/include/linux/random.h
  12087. --- linux-4.4.13.orig/include/linux/random.h 2016-06-08 03:14:51.000000000 +0200
  12088. +++ linux-4.4.13/include/linux/random.h 2016-06-22 21:55:08.034523867 +0200
  12089. @@ -20,7 +20,7 @@
  12090. extern void add_device_randomness(const void *, unsigned int);
  12091. extern void add_input_randomness(unsigned int type, unsigned int code,
  12092. unsigned int value);
  12093. -extern void add_interrupt_randomness(int irq, int irq_flags);
  12094. +extern void add_interrupt_randomness(int irq, int irq_flags, __u64 ip);
  12095. extern void get_random_bytes(void *buf, int nbytes);
  12096. extern int add_random_ready_callback(struct random_ready_callback *rdy);
  12097. diff -Nur linux-4.4.13.orig/include/linux/rbtree.h linux-4.4.13/include/linux/rbtree.h
  12098. --- linux-4.4.13.orig/include/linux/rbtree.h 2016-06-08 03:14:51.000000000 +0200
  12099. +++ linux-4.4.13/include/linux/rbtree.h 2016-06-22 21:55:08.034523867 +0200
  12100. @@ -31,7 +31,6 @@
  12101. #include <linux/kernel.h>
  12102. #include <linux/stddef.h>
  12103. -#include <linux/rcupdate.h>
  12104. struct rb_node {
  12105. unsigned long __rb_parent_color;
  12106. @@ -86,14 +85,8 @@
  12107. *rb_link = node;
  12108. }
  12109. -static inline void rb_link_node_rcu(struct rb_node *node, struct rb_node *parent,
  12110. - struct rb_node **rb_link)
  12111. -{
  12112. - node->__rb_parent_color = (unsigned long)parent;
  12113. - node->rb_left = node->rb_right = NULL;
  12114. -
  12115. - rcu_assign_pointer(*rb_link, node);
  12116. -}
  12117. +void rb_link_node_rcu(struct rb_node *node, struct rb_node *parent,
  12118. + struct rb_node **rb_link);
  12119. #define rb_entry_safe(ptr, type, member) \
  12120. ({ typeof(ptr) ____ptr = (ptr); \
  12121. diff -Nur linux-4.4.13.orig/include/linux/rcupdate.h linux-4.4.13/include/linux/rcupdate.h
  12122. --- linux-4.4.13.orig/include/linux/rcupdate.h 2016-06-08 03:14:51.000000000 +0200
  12123. +++ linux-4.4.13/include/linux/rcupdate.h 2016-06-22 21:55:08.034523867 +0200
  12124. @@ -169,6 +169,9 @@
  12125. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  12126. +#ifdef CONFIG_PREEMPT_RT_FULL
  12127. +#define call_rcu_bh call_rcu
  12128. +#else
  12129. /**
  12130. * call_rcu_bh() - Queue an RCU for invocation after a quicker grace period.
  12131. * @head: structure to be used for queueing the RCU updates.
  12132. @@ -192,6 +195,7 @@
  12133. */
  12134. void call_rcu_bh(struct rcu_head *head,
  12135. rcu_callback_t func);
  12136. +#endif
  12137. /**
  12138. * call_rcu_sched() - Queue an RCU for invocation after sched grace period.
  12139. @@ -292,6 +296,11 @@
  12140. * types of kernel builds, the rcu_read_lock() nesting depth is unknowable.
  12141. */
  12142. #define rcu_preempt_depth() (current->rcu_read_lock_nesting)
  12143. +#ifndef CONFIG_PREEMPT_RT_FULL
  12144. +#define sched_rcu_preempt_depth() rcu_preempt_depth()
  12145. +#else
  12146. +static inline int sched_rcu_preempt_depth(void) { return 0; }
  12147. +#endif
  12148. #else /* #ifdef CONFIG_PREEMPT_RCU */
  12149. @@ -317,6 +326,8 @@
  12150. return 0;
  12151. }
  12152. +#define sched_rcu_preempt_depth() rcu_preempt_depth()
  12153. +
  12154. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  12155. /* Internal to kernel */
  12156. @@ -489,7 +500,14 @@
  12157. int debug_lockdep_rcu_enabled(void);
  12158. int rcu_read_lock_held(void);
  12159. +#ifdef CONFIG_PREEMPT_RT_FULL
  12160. +static inline int rcu_read_lock_bh_held(void)
  12161. +{
  12162. + return rcu_read_lock_held();
  12163. +}
  12164. +#else
  12165. int rcu_read_lock_bh_held(void);
  12166. +#endif
  12167. /**
  12168. * rcu_read_lock_sched_held() - might we be in RCU-sched read-side critical section?
  12169. @@ -937,10 +955,14 @@
  12170. static inline void rcu_read_lock_bh(void)
  12171. {
  12172. local_bh_disable();
  12173. +#ifdef CONFIG_PREEMPT_RT_FULL
  12174. + rcu_read_lock();
  12175. +#else
  12176. __acquire(RCU_BH);
  12177. rcu_lock_acquire(&rcu_bh_lock_map);
  12178. RCU_LOCKDEP_WARN(!rcu_is_watching(),
  12179. "rcu_read_lock_bh() used illegally while idle");
  12180. +#endif
  12181. }
  12182. /*
  12183. @@ -950,10 +972,14 @@
  12184. */
  12185. static inline void rcu_read_unlock_bh(void)
  12186. {
  12187. +#ifdef CONFIG_PREEMPT_RT_FULL
  12188. + rcu_read_unlock();
  12189. +#else
  12190. RCU_LOCKDEP_WARN(!rcu_is_watching(),
  12191. "rcu_read_unlock_bh() used illegally while idle");
  12192. rcu_lock_release(&rcu_bh_lock_map);
  12193. __release(RCU_BH);
  12194. +#endif
  12195. local_bh_enable();
  12196. }
  12197. diff -Nur linux-4.4.13.orig/include/linux/rcutree.h linux-4.4.13/include/linux/rcutree.h
  12198. --- linux-4.4.13.orig/include/linux/rcutree.h 2016-06-08 03:14:51.000000000 +0200
  12199. +++ linux-4.4.13/include/linux/rcutree.h 2016-06-22 21:55:08.034523867 +0200
  12200. @@ -44,7 +44,11 @@
  12201. rcu_note_context_switch();
  12202. }
  12203. +#ifdef CONFIG_PREEMPT_RT_FULL
  12204. +# define synchronize_rcu_bh synchronize_rcu
  12205. +#else
  12206. void synchronize_rcu_bh(void);
  12207. +#endif
  12208. void synchronize_sched_expedited(void);
  12209. void synchronize_rcu_expedited(void);
  12210. @@ -72,7 +76,11 @@
  12211. }
  12212. void rcu_barrier(void);
  12213. +#ifdef CONFIG_PREEMPT_RT_FULL
  12214. +# define rcu_barrier_bh rcu_barrier
  12215. +#else
  12216. void rcu_barrier_bh(void);
  12217. +#endif
  12218. void rcu_barrier_sched(void);
  12219. unsigned long get_state_synchronize_rcu(void);
  12220. void cond_synchronize_rcu(unsigned long oldstate);
  12221. @@ -85,12 +93,10 @@
  12222. unsigned long rcu_batches_started_bh(void);
  12223. unsigned long rcu_batches_started_sched(void);
  12224. unsigned long rcu_batches_completed(void);
  12225. -unsigned long rcu_batches_completed_bh(void);
  12226. unsigned long rcu_batches_completed_sched(void);
  12227. void show_rcu_gp_kthreads(void);
  12228. void rcu_force_quiescent_state(void);
  12229. -void rcu_bh_force_quiescent_state(void);
  12230. void rcu_sched_force_quiescent_state(void);
  12231. void rcu_idle_enter(void);
  12232. @@ -105,6 +111,14 @@
  12233. bool rcu_is_watching(void);
  12234. +#ifndef CONFIG_PREEMPT_RT_FULL
  12235. +void rcu_bh_force_quiescent_state(void);
  12236. +unsigned long rcu_batches_completed_bh(void);
  12237. +#else
  12238. +# define rcu_bh_force_quiescent_state rcu_force_quiescent_state
  12239. +# define rcu_batches_completed_bh rcu_batches_completed
  12240. +#endif
  12241. +
  12242. void rcu_all_qs(void);
  12243. #endif /* __LINUX_RCUTREE_H */
  12244. diff -Nur linux-4.4.13.orig/include/linux/rtmutex.h linux-4.4.13/include/linux/rtmutex.h
  12245. --- linux-4.4.13.orig/include/linux/rtmutex.h 2016-06-08 03:14:51.000000000 +0200
  12246. +++ linux-4.4.13/include/linux/rtmutex.h 2016-06-22 21:55:08.034523867 +0200
  12247. @@ -13,11 +13,15 @@
  12248. #define __LINUX_RT_MUTEX_H
  12249. #include <linux/linkage.h>
  12250. +#include <linux/spinlock_types_raw.h>
  12251. #include <linux/rbtree.h>
  12252. -#include <linux/spinlock_types.h>
  12253. extern int max_lock_depth; /* for sysctl */
  12254. +#ifdef CONFIG_DEBUG_MUTEXES
  12255. +#include <linux/debug_locks.h>
  12256. +#endif
  12257. +
  12258. /**
  12259. * The rt_mutex structure
  12260. *
  12261. @@ -31,8 +35,8 @@
  12262. struct rb_root waiters;
  12263. struct rb_node *waiters_leftmost;
  12264. struct task_struct *owner;
  12265. -#ifdef CONFIG_DEBUG_RT_MUTEXES
  12266. int save_state;
  12267. +#ifdef CONFIG_DEBUG_RT_MUTEXES
  12268. const char *name, *file;
  12269. int line;
  12270. void *magic;
  12271. @@ -55,22 +59,33 @@
  12272. # define rt_mutex_debug_check_no_locks_held(task) do { } while (0)
  12273. #endif
  12274. +# define rt_mutex_init(mutex) \
  12275. + do { \
  12276. + raw_spin_lock_init(&(mutex)->wait_lock); \
  12277. + __rt_mutex_init(mutex, #mutex); \
  12278. + } while (0)
  12279. +
  12280. #ifdef CONFIG_DEBUG_RT_MUTEXES
  12281. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
  12282. , .name = #mutexname, .file = __FILE__, .line = __LINE__
  12283. -# define rt_mutex_init(mutex) __rt_mutex_init(mutex, __func__)
  12284. extern void rt_mutex_debug_task_free(struct task_struct *tsk);
  12285. #else
  12286. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
  12287. -# define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL)
  12288. # define rt_mutex_debug_task_free(t) do { } while (0)
  12289. #endif
  12290. -#define __RT_MUTEX_INITIALIZER(mutexname) \
  12291. - { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
  12292. +#define __RT_MUTEX_INITIALIZER_PLAIN(mutexname) \
  12293. + .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
  12294. , .waiters = RB_ROOT \
  12295. , .owner = NULL \
  12296. - __DEBUG_RT_MUTEX_INITIALIZER(mutexname)}
  12297. + __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
  12298. +
  12299. +#define __RT_MUTEX_INITIALIZER(mutexname) \
  12300. + { __RT_MUTEX_INITIALIZER_PLAIN(mutexname) }
  12301. +
  12302. +#define __RT_MUTEX_INITIALIZER_SAVE_STATE(mutexname) \
  12303. + { __RT_MUTEX_INITIALIZER_PLAIN(mutexname) \
  12304. + , .save_state = 1 }
  12305. #define DEFINE_RT_MUTEX(mutexname) \
  12306. struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
  12307. @@ -91,6 +106,7 @@
  12308. extern void rt_mutex_lock(struct rt_mutex *lock);
  12309. extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
  12310. +extern int rt_mutex_lock_killable(struct rt_mutex *lock);
  12311. extern int rt_mutex_timed_lock(struct rt_mutex *lock,
  12312. struct hrtimer_sleeper *timeout);
  12313. diff -Nur linux-4.4.13.orig/include/linux/rwlock_rt.h linux-4.4.13/include/linux/rwlock_rt.h
  12314. --- linux-4.4.13.orig/include/linux/rwlock_rt.h 1970-01-01 01:00:00.000000000 +0100
  12315. +++ linux-4.4.13/include/linux/rwlock_rt.h 2016-06-22 21:55:08.034523867 +0200
  12316. @@ -0,0 +1,99 @@
  12317. +#ifndef __LINUX_RWLOCK_RT_H
  12318. +#define __LINUX_RWLOCK_RT_H
  12319. +
  12320. +#ifndef __LINUX_SPINLOCK_H
  12321. +#error Do not include directly. Use spinlock.h
  12322. +#endif
  12323. +
  12324. +#define rwlock_init(rwl) \
  12325. +do { \
  12326. + static struct lock_class_key __key; \
  12327. + \
  12328. + rt_mutex_init(&(rwl)->lock); \
  12329. + __rt_rwlock_init(rwl, #rwl, &__key); \
  12330. +} while (0)
  12331. +
  12332. +extern void __lockfunc rt_write_lock(rwlock_t *rwlock);
  12333. +extern void __lockfunc rt_read_lock(rwlock_t *rwlock);
  12334. +extern int __lockfunc rt_write_trylock(rwlock_t *rwlock);
  12335. +extern int __lockfunc rt_write_trylock_irqsave(rwlock_t *trylock, unsigned long *flags);
  12336. +extern int __lockfunc rt_read_trylock(rwlock_t *rwlock);
  12337. +extern void __lockfunc rt_write_unlock(rwlock_t *rwlock);
  12338. +extern void __lockfunc rt_read_unlock(rwlock_t *rwlock);
  12339. +extern unsigned long __lockfunc rt_write_lock_irqsave(rwlock_t *rwlock);
  12340. +extern unsigned long __lockfunc rt_read_lock_irqsave(rwlock_t *rwlock);
  12341. +extern void __rt_rwlock_init(rwlock_t *rwlock, char *name, struct lock_class_key *key);
  12342. +
  12343. +#define read_trylock(lock) __cond_lock(lock, rt_read_trylock(lock))
  12344. +#define write_trylock(lock) __cond_lock(lock, rt_write_trylock(lock))
  12345. +
  12346. +#define write_trylock_irqsave(lock, flags) \
  12347. + __cond_lock(lock, rt_write_trylock_irqsave(lock, &flags))
  12348. +
  12349. +#define read_lock_irqsave(lock, flags) \
  12350. + do { \
  12351. + typecheck(unsigned long, flags); \
  12352. + flags = rt_read_lock_irqsave(lock); \
  12353. + } while (0)
  12354. +
  12355. +#define write_lock_irqsave(lock, flags) \
  12356. + do { \
  12357. + typecheck(unsigned long, flags); \
  12358. + flags = rt_write_lock_irqsave(lock); \
  12359. + } while (0)
  12360. +
  12361. +#define read_lock(lock) rt_read_lock(lock)
  12362. +
  12363. +#define read_lock_bh(lock) \
  12364. + do { \
  12365. + local_bh_disable(); \
  12366. + rt_read_lock(lock); \
  12367. + } while (0)
  12368. +
  12369. +#define read_lock_irq(lock) read_lock(lock)
  12370. +
  12371. +#define write_lock(lock) rt_write_lock(lock)
  12372. +
  12373. +#define write_lock_bh(lock) \
  12374. + do { \
  12375. + local_bh_disable(); \
  12376. + rt_write_lock(lock); \
  12377. + } while (0)
  12378. +
  12379. +#define write_lock_irq(lock) write_lock(lock)
  12380. +
  12381. +#define read_unlock(lock) rt_read_unlock(lock)
  12382. +
  12383. +#define read_unlock_bh(lock) \
  12384. + do { \
  12385. + rt_read_unlock(lock); \
  12386. + local_bh_enable(); \
  12387. + } while (0)
  12388. +
  12389. +#define read_unlock_irq(lock) read_unlock(lock)
  12390. +
  12391. +#define write_unlock(lock) rt_write_unlock(lock)
  12392. +
  12393. +#define write_unlock_bh(lock) \
  12394. + do { \
  12395. + rt_write_unlock(lock); \
  12396. + local_bh_enable(); \
  12397. + } while (0)
  12398. +
  12399. +#define write_unlock_irq(lock) write_unlock(lock)
  12400. +
  12401. +#define read_unlock_irqrestore(lock, flags) \
  12402. + do { \
  12403. + typecheck(unsigned long, flags); \
  12404. + (void) flags; \
  12405. + rt_read_unlock(lock); \
  12406. + } while (0)
  12407. +
  12408. +#define write_unlock_irqrestore(lock, flags) \
  12409. + do { \
  12410. + typecheck(unsigned long, flags); \
  12411. + (void) flags; \
  12412. + rt_write_unlock(lock); \
  12413. + } while (0)
  12414. +
  12415. +#endif
  12416. diff -Nur linux-4.4.13.orig/include/linux/rwlock_types.h linux-4.4.13/include/linux/rwlock_types.h
  12417. --- linux-4.4.13.orig/include/linux/rwlock_types.h 2016-06-08 03:14:51.000000000 +0200
  12418. +++ linux-4.4.13/include/linux/rwlock_types.h 2016-06-22 21:55:08.034523867 +0200
  12419. @@ -1,6 +1,10 @@
  12420. #ifndef __LINUX_RWLOCK_TYPES_H
  12421. #define __LINUX_RWLOCK_TYPES_H
  12422. +#if !defined(__LINUX_SPINLOCK_TYPES_H)
  12423. +# error "Do not include directly, include spinlock_types.h"
  12424. +#endif
  12425. +
  12426. /*
  12427. * include/linux/rwlock_types.h - generic rwlock type definitions
  12428. * and initializers
  12429. @@ -43,6 +47,7 @@
  12430. RW_DEP_MAP_INIT(lockname) }
  12431. #endif
  12432. -#define DEFINE_RWLOCK(x) rwlock_t x = __RW_LOCK_UNLOCKED(x)
  12433. +#define DEFINE_RWLOCK(name) \
  12434. + rwlock_t name __cacheline_aligned_in_smp = __RW_LOCK_UNLOCKED(name)
  12435. #endif /* __LINUX_RWLOCK_TYPES_H */
  12436. diff -Nur linux-4.4.13.orig/include/linux/rwlock_types_rt.h linux-4.4.13/include/linux/rwlock_types_rt.h
  12437. --- linux-4.4.13.orig/include/linux/rwlock_types_rt.h 1970-01-01 01:00:00.000000000 +0100
  12438. +++ linux-4.4.13/include/linux/rwlock_types_rt.h 2016-06-22 21:55:08.034523867 +0200
  12439. @@ -0,0 +1,33 @@
  12440. +#ifndef __LINUX_RWLOCK_TYPES_RT_H
  12441. +#define __LINUX_RWLOCK_TYPES_RT_H
  12442. +
  12443. +#ifndef __LINUX_SPINLOCK_TYPES_H
  12444. +#error "Do not include directly. Include spinlock_types.h instead"
  12445. +#endif
  12446. +
  12447. +/*
  12448. + * rwlocks - rtmutex which allows single reader recursion
  12449. + */
  12450. +typedef struct {
  12451. + struct rt_mutex lock;
  12452. + int read_depth;
  12453. + unsigned int break_lock;
  12454. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  12455. + struct lockdep_map dep_map;
  12456. +#endif
  12457. +} rwlock_t;
  12458. +
  12459. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  12460. +# define RW_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  12461. +#else
  12462. +# define RW_DEP_MAP_INIT(lockname)
  12463. +#endif
  12464. +
  12465. +#define __RW_LOCK_UNLOCKED(name) \
  12466. + { .lock = __RT_MUTEX_INITIALIZER_SAVE_STATE(name.lock), \
  12467. + RW_DEP_MAP_INIT(name) }
  12468. +
  12469. +#define DEFINE_RWLOCK(name) \
  12470. + rwlock_t name __cacheline_aligned_in_smp = __RW_LOCK_UNLOCKED(name)
  12471. +
  12472. +#endif
  12473. diff -Nur linux-4.4.13.orig/include/linux/rwsem.h linux-4.4.13/include/linux/rwsem.h
  12474. --- linux-4.4.13.orig/include/linux/rwsem.h 2016-06-08 03:14:51.000000000 +0200
  12475. +++ linux-4.4.13/include/linux/rwsem.h 2016-06-22 21:55:08.034523867 +0200
  12476. @@ -18,6 +18,10 @@
  12477. #include <linux/osq_lock.h>
  12478. #endif
  12479. +#ifdef CONFIG_PREEMPT_RT_FULL
  12480. +#include <linux/rwsem_rt.h>
  12481. +#else /* PREEMPT_RT_FULL */
  12482. +
  12483. struct rw_semaphore;
  12484. #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
  12485. @@ -177,4 +181,6 @@
  12486. # define up_read_non_owner(sem) up_read(sem)
  12487. #endif
  12488. +#endif /* !PREEMPT_RT_FULL */
  12489. +
  12490. #endif /* _LINUX_RWSEM_H */
  12491. diff -Nur linux-4.4.13.orig/include/linux/rwsem_rt.h linux-4.4.13/include/linux/rwsem_rt.h
  12492. --- linux-4.4.13.orig/include/linux/rwsem_rt.h 1970-01-01 01:00:00.000000000 +0100
  12493. +++ linux-4.4.13/include/linux/rwsem_rt.h 2016-06-22 21:55:08.034523867 +0200
  12494. @@ -0,0 +1,152 @@
  12495. +#ifndef _LINUX_RWSEM_RT_H
  12496. +#define _LINUX_RWSEM_RT_H
  12497. +
  12498. +#ifndef _LINUX_RWSEM_H
  12499. +#error "Include rwsem.h"
  12500. +#endif
  12501. +
  12502. +/*
  12503. + * RW-semaphores are a spinlock plus a reader-depth count.
  12504. + *
  12505. + * Note that the semantics are different from the usual
  12506. + * Linux rw-sems, in PREEMPT_RT mode we do not allow
  12507. + * multiple readers to hold the lock at once, we only allow
  12508. + * a read-lock owner to read-lock recursively. This is
  12509. + * better for latency, makes the implementation inherently
  12510. + * fair and makes it simpler as well.
  12511. + */
  12512. +
  12513. +#include <linux/rtmutex.h>
  12514. +
  12515. +struct rw_semaphore {
  12516. + struct rt_mutex lock;
  12517. + int read_depth;
  12518. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  12519. + struct lockdep_map dep_map;
  12520. +#endif
  12521. +};
  12522. +
  12523. +#define __RWSEM_INITIALIZER(name) \
  12524. + { .lock = __RT_MUTEX_INITIALIZER(name.lock), \
  12525. + RW_DEP_MAP_INIT(name) }
  12526. +
  12527. +#define DECLARE_RWSEM(lockname) \
  12528. + struct rw_semaphore lockname = __RWSEM_INITIALIZER(lockname)
  12529. +
  12530. +extern void __rt_rwsem_init(struct rw_semaphore *rwsem, const char *name,
  12531. + struct lock_class_key *key);
  12532. +
  12533. +#define __rt_init_rwsem(sem, name, key) \
  12534. + do { \
  12535. + rt_mutex_init(&(sem)->lock); \
  12536. + __rt_rwsem_init((sem), (name), (key));\
  12537. + } while (0)
  12538. +
  12539. +#define __init_rwsem(sem, name, key) __rt_init_rwsem(sem, name, key)
  12540. +
  12541. +# define rt_init_rwsem(sem) \
  12542. +do { \
  12543. + static struct lock_class_key __key; \
  12544. + \
  12545. + __rt_init_rwsem((sem), #sem, &__key); \
  12546. +} while (0)
  12547. +
  12548. +extern void rt_down_write(struct rw_semaphore *rwsem);
  12549. +extern void rt_down_read_nested(struct rw_semaphore *rwsem, int subclass);
  12550. +extern void rt_down_write_nested(struct rw_semaphore *rwsem, int subclass);
  12551. +extern void rt_down_write_nested_lock(struct rw_semaphore *rwsem,
  12552. + struct lockdep_map *nest);
  12553. +extern void rt__down_read(struct rw_semaphore *rwsem);
  12554. +extern void rt_down_read(struct rw_semaphore *rwsem);
  12555. +extern int rt_down_write_trylock(struct rw_semaphore *rwsem);
  12556. +extern int rt__down_read_trylock(struct rw_semaphore *rwsem);
  12557. +extern int rt_down_read_trylock(struct rw_semaphore *rwsem);
  12558. +extern void __rt_up_read(struct rw_semaphore *rwsem);
  12559. +extern void rt_up_read(struct rw_semaphore *rwsem);
  12560. +extern void rt_up_write(struct rw_semaphore *rwsem);
  12561. +extern void rt_downgrade_write(struct rw_semaphore *rwsem);
  12562. +
  12563. +#define init_rwsem(sem) rt_init_rwsem(sem)
  12564. +#define rwsem_is_locked(s) rt_mutex_is_locked(&(s)->lock)
  12565. +
  12566. +static inline int rwsem_is_contended(struct rw_semaphore *sem)
  12567. +{
  12568. + /* rt_mutex_has_waiters() */
  12569. + return !RB_EMPTY_ROOT(&sem->lock.waiters);
  12570. +}
  12571. +
  12572. +static inline void __down_read(struct rw_semaphore *sem)
  12573. +{
  12574. + rt__down_read(sem);
  12575. +}
  12576. +
  12577. +static inline void down_read(struct rw_semaphore *sem)
  12578. +{
  12579. + rt_down_read(sem);
  12580. +}
  12581. +
  12582. +static inline int __down_read_trylock(struct rw_semaphore *sem)
  12583. +{
  12584. + return rt__down_read_trylock(sem);
  12585. +}
  12586. +
  12587. +static inline int down_read_trylock(struct rw_semaphore *sem)
  12588. +{
  12589. + return rt_down_read_trylock(sem);
  12590. +}
  12591. +
  12592. +static inline void down_write(struct rw_semaphore *sem)
  12593. +{
  12594. + rt_down_write(sem);
  12595. +}
  12596. +
  12597. +static inline int down_write_trylock(struct rw_semaphore *sem)
  12598. +{
  12599. + return rt_down_write_trylock(sem);
  12600. +}
  12601. +
  12602. +static inline void __up_read(struct rw_semaphore *sem)
  12603. +{
  12604. + __rt_up_read(sem);
  12605. +}
  12606. +
  12607. +static inline void up_read(struct rw_semaphore *sem)
  12608. +{
  12609. + rt_up_read(sem);
  12610. +}
  12611. +
  12612. +static inline void up_write(struct rw_semaphore *sem)
  12613. +{
  12614. + rt_up_write(sem);
  12615. +}
  12616. +
  12617. +static inline void downgrade_write(struct rw_semaphore *sem)
  12618. +{
  12619. + rt_downgrade_write(sem);
  12620. +}
  12621. +
  12622. +static inline void down_read_nested(struct rw_semaphore *sem, int subclass)
  12623. +{
  12624. + return rt_down_read_nested(sem, subclass);
  12625. +}
  12626. +
  12627. +static inline void down_write_nested(struct rw_semaphore *sem, int subclass)
  12628. +{
  12629. + rt_down_write_nested(sem, subclass);
  12630. +}
  12631. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  12632. +static inline void down_write_nest_lock(struct rw_semaphore *sem,
  12633. + struct rw_semaphore *nest_lock)
  12634. +{
  12635. + rt_down_write_nested_lock(sem, &nest_lock->dep_map);
  12636. +}
  12637. +
  12638. +#else
  12639. +
  12640. +static inline void down_write_nest_lock(struct rw_semaphore *sem,
  12641. + struct rw_semaphore *nest_lock)
  12642. +{
  12643. + rt_down_write_nested_lock(sem, NULL);
  12644. +}
  12645. +#endif
  12646. +#endif
  12647. diff -Nur linux-4.4.13.orig/include/linux/sched.h linux-4.4.13/include/linux/sched.h
  12648. --- linux-4.4.13.orig/include/linux/sched.h 2016-06-08 03:14:51.000000000 +0200
  12649. +++ linux-4.4.13/include/linux/sched.h 2016-06-22 21:55:08.038523867 +0200
  12650. @@ -26,6 +26,7 @@
  12651. #include <linux/nodemask.h>
  12652. #include <linux/mm_types.h>
  12653. #include <linux/preempt.h>
  12654. +#include <asm/kmap_types.h>
  12655. #include <asm/page.h>
  12656. #include <asm/ptrace.h>
  12657. @@ -182,8 +183,6 @@
  12658. static inline void update_cpu_load_nohz(void) { }
  12659. #endif
  12660. -extern unsigned long get_parent_ip(unsigned long addr);
  12661. -
  12662. extern void dump_cpu_task(int cpu);
  12663. struct seq_file;
  12664. @@ -242,10 +241,7 @@
  12665. TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
  12666. __TASK_TRACED | EXIT_ZOMBIE | EXIT_DEAD)
  12667. -#define task_is_traced(task) ((task->state & __TASK_TRACED) != 0)
  12668. #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0)
  12669. -#define task_is_stopped_or_traced(task) \
  12670. - ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
  12671. #define task_contributes_to_load(task) \
  12672. ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
  12673. (task->flags & PF_FROZEN) == 0 && \
  12674. @@ -311,6 +307,11 @@
  12675. #endif
  12676. +#define __set_current_state_no_track(state_value) \
  12677. + do { current->state = (state_value); } while (0)
  12678. +#define set_current_state_no_track(state_value) \
  12679. + set_mb(current->state, (state_value))
  12680. +
  12681. /* Task command name length */
  12682. #define TASK_COMM_LEN 16
  12683. @@ -970,8 +971,18 @@
  12684. struct wake_q_head name = { WAKE_Q_TAIL, &name.first }
  12685. extern void wake_q_add(struct wake_q_head *head,
  12686. - struct task_struct *task);
  12687. -extern void wake_up_q(struct wake_q_head *head);
  12688. + struct task_struct *task);
  12689. +extern void __wake_up_q(struct wake_q_head *head, bool sleeper);
  12690. +
  12691. +static inline void wake_up_q(struct wake_q_head *head)
  12692. +{
  12693. + __wake_up_q(head, false);
  12694. +}
  12695. +
  12696. +static inline void wake_up_q_sleeper(struct wake_q_head *head)
  12697. +{
  12698. + __wake_up_q(head, true);
  12699. +}
  12700. /*
  12701. * sched-domains (multiprocessor balancing) declarations:
  12702. @@ -1379,6 +1390,7 @@
  12703. struct task_struct {
  12704. volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
  12705. + volatile long saved_state; /* saved state for "spinlock sleepers" */
  12706. void *stack;
  12707. atomic_t usage;
  12708. unsigned int flags; /* per process flags, defined below */
  12709. @@ -1415,6 +1427,12 @@
  12710. #endif
  12711. unsigned int policy;
  12712. +#ifdef CONFIG_PREEMPT_RT_FULL
  12713. + int migrate_disable;
  12714. +# ifdef CONFIG_SCHED_DEBUG
  12715. + int migrate_disable_atomic;
  12716. +# endif
  12717. +#endif
  12718. int nr_cpus_allowed;
  12719. cpumask_t cpus_allowed;
  12720. @@ -1522,11 +1540,14 @@
  12721. cputime_t gtime;
  12722. struct prev_cputime prev_cputime;
  12723. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  12724. - seqlock_t vtime_seqlock;
  12725. + seqcount_t vtime_seqcount;
  12726. unsigned long long vtime_snap;
  12727. enum {
  12728. - VTIME_SLEEPING = 0,
  12729. + /* Task is sleeping or running in a CPU with VTIME inactive */
  12730. + VTIME_INACTIVE = 0,
  12731. + /* Task runs in userspace in a CPU with VTIME active */
  12732. VTIME_USER,
  12733. + /* Task runs in kernelspace in a CPU with VTIME active */
  12734. VTIME_SYS,
  12735. } vtime_snap_whence;
  12736. #endif
  12737. @@ -1538,6 +1559,9 @@
  12738. struct task_cputime cputime_expires;
  12739. struct list_head cpu_timers[3];
  12740. +#ifdef CONFIG_PREEMPT_RT_BASE
  12741. + struct task_struct *posix_timer_list;
  12742. +#endif
  12743. /* process credentials */
  12744. const struct cred __rcu *real_cred; /* objective and real subjective task
  12745. @@ -1568,10 +1592,15 @@
  12746. /* signal handlers */
  12747. struct signal_struct *signal;
  12748. struct sighand_struct *sighand;
  12749. + struct sigqueue *sigqueue_cache;
  12750. sigset_t blocked, real_blocked;
  12751. sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */
  12752. struct sigpending pending;
  12753. +#ifdef CONFIG_PREEMPT_RT_FULL
  12754. + /* TODO: move me into ->restart_block ? */
  12755. + struct siginfo forced_info;
  12756. +#endif
  12757. unsigned long sas_ss_sp;
  12758. size_t sas_ss_size;
  12759. @@ -1795,6 +1824,12 @@
  12760. unsigned long trace;
  12761. /* bitmask and counter of trace recursion */
  12762. unsigned long trace_recursion;
  12763. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  12764. + u64 preempt_timestamp_hist;
  12765. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  12766. + long timer_offset;
  12767. +#endif
  12768. +#endif
  12769. #endif /* CONFIG_TRACING */
  12770. #ifdef CONFIG_MEMCG
  12771. struct mem_cgroup *memcg_in_oom;
  12772. @@ -1811,9 +1846,23 @@
  12773. unsigned int sequential_io;
  12774. unsigned int sequential_io_avg;
  12775. #endif
  12776. +#ifdef CONFIG_PREEMPT_RT_BASE
  12777. + struct rcu_head put_rcu;
  12778. + int softirq_nestcnt;
  12779. + unsigned int softirqs_raised;
  12780. +#endif
  12781. +#ifdef CONFIG_PREEMPT_RT_FULL
  12782. +# if defined CONFIG_HIGHMEM || defined CONFIG_X86_32
  12783. + int kmap_idx;
  12784. + pte_t kmap_pte[KM_TYPE_NR];
  12785. +# endif
  12786. +#endif
  12787. #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
  12788. unsigned long task_state_change;
  12789. #endif
  12790. +#ifdef CONFIG_PREEMPT_RT_FULL
  12791. + int xmit_recursion;
  12792. +#endif
  12793. int pagefault_disabled;
  12794. /* CPU-specific state of this task */
  12795. struct thread_struct thread;
  12796. @@ -1831,9 +1880,6 @@
  12797. # define arch_task_struct_size (sizeof(struct task_struct))
  12798. #endif
  12799. -/* Future-safe accessor for struct task_struct's cpus_allowed. */
  12800. -#define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
  12801. -
  12802. #define TNF_MIGRATED 0x01
  12803. #define TNF_NO_GROUP 0x02
  12804. #define TNF_SHARED 0x04
  12805. @@ -2023,6 +2069,15 @@
  12806. extern void free_task(struct task_struct *tsk);
  12807. #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
  12808. +#ifdef CONFIG_PREEMPT_RT_BASE
  12809. +extern void __put_task_struct_cb(struct rcu_head *rhp);
  12810. +
  12811. +static inline void put_task_struct(struct task_struct *t)
  12812. +{
  12813. + if (atomic_dec_and_test(&t->usage))
  12814. + call_rcu(&t->put_rcu, __put_task_struct_cb);
  12815. +}
  12816. +#else
  12817. extern void __put_task_struct(struct task_struct *t);
  12818. static inline void put_task_struct(struct task_struct *t)
  12819. @@ -2030,6 +2085,7 @@
  12820. if (atomic_dec_and_test(&t->usage))
  12821. __put_task_struct(t);
  12822. }
  12823. +#endif
  12824. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  12825. extern void task_cputime(struct task_struct *t,
  12826. @@ -2068,6 +2124,7 @@
  12827. /*
  12828. * Per process flags
  12829. */
  12830. +#define PF_IN_SOFTIRQ 0x00000001 /* Task is serving softirq */
  12831. #define PF_EXITING 0x00000004 /* getting shut down */
  12832. #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */
  12833. #define PF_VCPU 0x00000010 /* I'm a virtual CPU */
  12834. @@ -2232,6 +2289,10 @@
  12835. extern int set_cpus_allowed_ptr(struct task_struct *p,
  12836. const struct cpumask *new_mask);
  12837. +int migrate_me(void);
  12838. +void tell_sched_cpu_down_begin(int cpu);
  12839. +void tell_sched_cpu_down_done(int cpu);
  12840. +
  12841. #else
  12842. static inline void do_set_cpus_allowed(struct task_struct *p,
  12843. const struct cpumask *new_mask)
  12844. @@ -2244,6 +2305,9 @@
  12845. return -EINVAL;
  12846. return 0;
  12847. }
  12848. +static inline int migrate_me(void) { return 0; }
  12849. +static inline void tell_sched_cpu_down_begin(int cpu) { }
  12850. +static inline void tell_sched_cpu_down_done(int cpu) { }
  12851. #endif
  12852. #ifdef CONFIG_NO_HZ_COMMON
  12853. @@ -2453,6 +2517,7 @@
  12854. extern int wake_up_state(struct task_struct *tsk, unsigned int state);
  12855. extern int wake_up_process(struct task_struct *tsk);
  12856. +extern int wake_up_lock_sleeper(struct task_struct * tsk);
  12857. extern void wake_up_new_task(struct task_struct *tsk);
  12858. #ifdef CONFIG_SMP
  12859. extern void kick_process(struct task_struct *tsk);
  12860. @@ -2576,12 +2641,24 @@
  12861. /* mmdrop drops the mm and the page tables */
  12862. extern void __mmdrop(struct mm_struct *);
  12863. +
  12864. static inline void mmdrop(struct mm_struct * mm)
  12865. {
  12866. if (unlikely(atomic_dec_and_test(&mm->mm_count)))
  12867. __mmdrop(mm);
  12868. }
  12869. +#ifdef CONFIG_PREEMPT_RT_BASE
  12870. +extern void __mmdrop_delayed(struct rcu_head *rhp);
  12871. +static inline void mmdrop_delayed(struct mm_struct *mm)
  12872. +{
  12873. + if (atomic_dec_and_test(&mm->mm_count))
  12874. + call_rcu(&mm->delayed_drop, __mmdrop_delayed);
  12875. +}
  12876. +#else
  12877. +# define mmdrop_delayed(mm) mmdrop(mm)
  12878. +#endif
  12879. +
  12880. /* mmput gets rid of the mappings and all user-space */
  12881. extern void mmput(struct mm_struct *);
  12882. /* Grab a reference to a task's mm, if it is not already going away */
  12883. @@ -2891,6 +2968,43 @@
  12884. return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
  12885. }
  12886. +#ifdef CONFIG_PREEMPT_LAZY
  12887. +static inline void set_tsk_need_resched_lazy(struct task_struct *tsk)
  12888. +{
  12889. + set_tsk_thread_flag(tsk,TIF_NEED_RESCHED_LAZY);
  12890. +}
  12891. +
  12892. +static inline void clear_tsk_need_resched_lazy(struct task_struct *tsk)
  12893. +{
  12894. + clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED_LAZY);
  12895. +}
  12896. +
  12897. +static inline int test_tsk_need_resched_lazy(struct task_struct *tsk)
  12898. +{
  12899. + return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED_LAZY));
  12900. +}
  12901. +
  12902. +static inline int need_resched_lazy(void)
  12903. +{
  12904. + return test_thread_flag(TIF_NEED_RESCHED_LAZY);
  12905. +}
  12906. +
  12907. +static inline int need_resched_now(void)
  12908. +{
  12909. + return test_thread_flag(TIF_NEED_RESCHED);
  12910. +}
  12911. +
  12912. +#else
  12913. +static inline void clear_tsk_need_resched_lazy(struct task_struct *tsk) { }
  12914. +static inline int need_resched_lazy(void) { return 0; }
  12915. +
  12916. +static inline int need_resched_now(void)
  12917. +{
  12918. + return test_thread_flag(TIF_NEED_RESCHED);
  12919. +}
  12920. +
  12921. +#endif
  12922. +
  12923. static inline int restart_syscall(void)
  12924. {
  12925. set_tsk_thread_flag(current, TIF_SIGPENDING);
  12926. @@ -2922,6 +3036,51 @@
  12927. return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
  12928. }
  12929. +static inline bool __task_is_stopped_or_traced(struct task_struct *task)
  12930. +{
  12931. + if (task->state & (__TASK_STOPPED | __TASK_TRACED))
  12932. + return true;
  12933. +#ifdef CONFIG_PREEMPT_RT_FULL
  12934. + if (task->saved_state & (__TASK_STOPPED | __TASK_TRACED))
  12935. + return true;
  12936. +#endif
  12937. + return false;
  12938. +}
  12939. +
  12940. +static inline bool task_is_stopped_or_traced(struct task_struct *task)
  12941. +{
  12942. + bool traced_stopped;
  12943. +
  12944. +#ifdef CONFIG_PREEMPT_RT_FULL
  12945. + unsigned long flags;
  12946. +
  12947. + raw_spin_lock_irqsave(&task->pi_lock, flags);
  12948. + traced_stopped = __task_is_stopped_or_traced(task);
  12949. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  12950. +#else
  12951. + traced_stopped = __task_is_stopped_or_traced(task);
  12952. +#endif
  12953. + return traced_stopped;
  12954. +}
  12955. +
  12956. +static inline bool task_is_traced(struct task_struct *task)
  12957. +{
  12958. + bool traced = false;
  12959. +
  12960. + if (task->state & __TASK_TRACED)
  12961. + return true;
  12962. +#ifdef CONFIG_PREEMPT_RT_FULL
  12963. + /* in case the task is sleeping on tasklist_lock */
  12964. + raw_spin_lock_irq(&task->pi_lock);
  12965. + if (task->state & __TASK_TRACED)
  12966. + traced = true;
  12967. + else if (task->saved_state & __TASK_TRACED)
  12968. + traced = true;
  12969. + raw_spin_unlock_irq(&task->pi_lock);
  12970. +#endif
  12971. + return traced;
  12972. +}
  12973. +
  12974. /*
  12975. * cond_resched() and cond_resched_lock(): latency reduction via
  12976. * explicit rescheduling in places that are safe. The return
  12977. @@ -2943,12 +3102,16 @@
  12978. __cond_resched_lock(lock); \
  12979. })
  12980. +#ifndef CONFIG_PREEMPT_RT_FULL
  12981. extern int __cond_resched_softirq(void);
  12982. #define cond_resched_softirq() ({ \
  12983. ___might_sleep(__FILE__, __LINE__, SOFTIRQ_DISABLE_OFFSET); \
  12984. __cond_resched_softirq(); \
  12985. })
  12986. +#else
  12987. +# define cond_resched_softirq() cond_resched()
  12988. +#endif
  12989. static inline void cond_resched_rcu(void)
  12990. {
  12991. @@ -3110,6 +3273,31 @@
  12992. #endif /* CONFIG_SMP */
  12993. +static inline int __migrate_disabled(struct task_struct *p)
  12994. +{
  12995. +#ifdef CONFIG_PREEMPT_RT_FULL
  12996. + return p->migrate_disable;
  12997. +#else
  12998. + return 0;
  12999. +#endif
  13000. +}
  13001. +
  13002. +/* Future-safe accessor for struct task_struct's cpus_allowed. */
  13003. +static inline const struct cpumask *tsk_cpus_allowed(struct task_struct *p)
  13004. +{
  13005. + if (__migrate_disabled(p))
  13006. + return cpumask_of(task_cpu(p));
  13007. +
  13008. + return &p->cpus_allowed;
  13009. +}
  13010. +
  13011. +static inline int tsk_nr_cpus_allowed(struct task_struct *p)
  13012. +{
  13013. + if (__migrate_disabled(p))
  13014. + return 1;
  13015. + return p->nr_cpus_allowed;
  13016. +}
  13017. +
  13018. extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
  13019. extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
  13020. diff -Nur linux-4.4.13.orig/include/linux/seqlock.h linux-4.4.13/include/linux/seqlock.h
  13021. --- linux-4.4.13.orig/include/linux/seqlock.h 2016-06-08 03:14:51.000000000 +0200
  13022. +++ linux-4.4.13/include/linux/seqlock.h 2016-06-22 21:55:08.038523867 +0200
  13023. @@ -220,20 +220,30 @@
  13024. return __read_seqcount_retry(s, start);
  13025. }
  13026. -
  13027. -
  13028. -static inline void raw_write_seqcount_begin(seqcount_t *s)
  13029. +static inline void __raw_write_seqcount_begin(seqcount_t *s)
  13030. {
  13031. s->sequence++;
  13032. smp_wmb();
  13033. }
  13034. -static inline void raw_write_seqcount_end(seqcount_t *s)
  13035. +static inline void raw_write_seqcount_begin(seqcount_t *s)
  13036. +{
  13037. + preempt_disable_rt();
  13038. + __raw_write_seqcount_begin(s);
  13039. +}
  13040. +
  13041. +static inline void __raw_write_seqcount_end(seqcount_t *s)
  13042. {
  13043. smp_wmb();
  13044. s->sequence++;
  13045. }
  13046. +static inline void raw_write_seqcount_end(seqcount_t *s)
  13047. +{
  13048. + __raw_write_seqcount_end(s);
  13049. + preempt_enable_rt();
  13050. +}
  13051. +
  13052. /**
  13053. * raw_write_seqcount_barrier - do a seq write barrier
  13054. * @s: pointer to seqcount_t
  13055. @@ -425,10 +435,32 @@
  13056. /*
  13057. * Read side functions for starting and finalizing a read side section.
  13058. */
  13059. +#ifndef CONFIG_PREEMPT_RT_FULL
  13060. static inline unsigned read_seqbegin(const seqlock_t *sl)
  13061. {
  13062. return read_seqcount_begin(&sl->seqcount);
  13063. }
  13064. +#else
  13065. +/*
  13066. + * Starvation safe read side for RT
  13067. + */
  13068. +static inline unsigned read_seqbegin(seqlock_t *sl)
  13069. +{
  13070. + unsigned ret;
  13071. +
  13072. +repeat:
  13073. + ret = ACCESS_ONCE(sl->seqcount.sequence);
  13074. + if (unlikely(ret & 1)) {
  13075. + /*
  13076. + * Take the lock and let the writer proceed (i.e. evtl
  13077. + * boost it), otherwise we could loop here forever.
  13078. + */
  13079. + spin_unlock_wait(&sl->lock);
  13080. + goto repeat;
  13081. + }
  13082. + return ret;
  13083. +}
  13084. +#endif
  13085. static inline unsigned read_seqretry(const seqlock_t *sl, unsigned start)
  13086. {
  13087. @@ -443,36 +475,36 @@
  13088. static inline void write_seqlock(seqlock_t *sl)
  13089. {
  13090. spin_lock(&sl->lock);
  13091. - write_seqcount_begin(&sl->seqcount);
  13092. + __raw_write_seqcount_begin(&sl->seqcount);
  13093. }
  13094. static inline void write_sequnlock(seqlock_t *sl)
  13095. {
  13096. - write_seqcount_end(&sl->seqcount);
  13097. + __raw_write_seqcount_end(&sl->seqcount);
  13098. spin_unlock(&sl->lock);
  13099. }
  13100. static inline void write_seqlock_bh(seqlock_t *sl)
  13101. {
  13102. spin_lock_bh(&sl->lock);
  13103. - write_seqcount_begin(&sl->seqcount);
  13104. + __raw_write_seqcount_begin(&sl->seqcount);
  13105. }
  13106. static inline void write_sequnlock_bh(seqlock_t *sl)
  13107. {
  13108. - write_seqcount_end(&sl->seqcount);
  13109. + __raw_write_seqcount_end(&sl->seqcount);
  13110. spin_unlock_bh(&sl->lock);
  13111. }
  13112. static inline void write_seqlock_irq(seqlock_t *sl)
  13113. {
  13114. spin_lock_irq(&sl->lock);
  13115. - write_seqcount_begin(&sl->seqcount);
  13116. + __raw_write_seqcount_begin(&sl->seqcount);
  13117. }
  13118. static inline void write_sequnlock_irq(seqlock_t *sl)
  13119. {
  13120. - write_seqcount_end(&sl->seqcount);
  13121. + __raw_write_seqcount_end(&sl->seqcount);
  13122. spin_unlock_irq(&sl->lock);
  13123. }
  13124. @@ -481,7 +513,7 @@
  13125. unsigned long flags;
  13126. spin_lock_irqsave(&sl->lock, flags);
  13127. - write_seqcount_begin(&sl->seqcount);
  13128. + __raw_write_seqcount_begin(&sl->seqcount);
  13129. return flags;
  13130. }
  13131. @@ -491,7 +523,7 @@
  13132. static inline void
  13133. write_sequnlock_irqrestore(seqlock_t *sl, unsigned long flags)
  13134. {
  13135. - write_seqcount_end(&sl->seqcount);
  13136. + __raw_write_seqcount_end(&sl->seqcount);
  13137. spin_unlock_irqrestore(&sl->lock, flags);
  13138. }
  13139. diff -Nur linux-4.4.13.orig/include/linux/signal.h linux-4.4.13/include/linux/signal.h
  13140. --- linux-4.4.13.orig/include/linux/signal.h 2016-06-08 03:14:51.000000000 +0200
  13141. +++ linux-4.4.13/include/linux/signal.h 2016-06-22 21:55:08.038523867 +0200
  13142. @@ -233,6 +233,7 @@
  13143. }
  13144. extern void flush_sigqueue(struct sigpending *queue);
  13145. +extern void flush_task_sigqueue(struct task_struct *tsk);
  13146. /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
  13147. static inline int valid_signal(unsigned long sig)
  13148. diff -Nur linux-4.4.13.orig/include/linux/skbuff.h linux-4.4.13/include/linux/skbuff.h
  13149. --- linux-4.4.13.orig/include/linux/skbuff.h 2016-06-08 03:14:51.000000000 +0200
  13150. +++ linux-4.4.13/include/linux/skbuff.h 2016-06-22 21:55:08.038523867 +0200
  13151. @@ -203,6 +203,7 @@
  13152. __u32 qlen;
  13153. spinlock_t lock;
  13154. + raw_spinlock_t raw_lock;
  13155. };
  13156. struct sk_buff;
  13157. @@ -1464,6 +1465,12 @@
  13158. __skb_queue_head_init(list);
  13159. }
  13160. +static inline void skb_queue_head_init_raw(struct sk_buff_head *list)
  13161. +{
  13162. + raw_spin_lock_init(&list->raw_lock);
  13163. + __skb_queue_head_init(list);
  13164. +}
  13165. +
  13166. static inline void skb_queue_head_init_class(struct sk_buff_head *list,
  13167. struct lock_class_key *class)
  13168. {
  13169. diff -Nur linux-4.4.13.orig/include/linux/smp.h linux-4.4.13/include/linux/smp.h
  13170. --- linux-4.4.13.orig/include/linux/smp.h 2016-06-08 03:14:51.000000000 +0200
  13171. +++ linux-4.4.13/include/linux/smp.h 2016-06-22 21:55:08.038523867 +0200
  13172. @@ -185,6 +185,9 @@
  13173. #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
  13174. #define put_cpu() preempt_enable()
  13175. +#define get_cpu_light() ({ migrate_disable(); smp_processor_id(); })
  13176. +#define put_cpu_light() migrate_enable()
  13177. +
  13178. /*
  13179. * Callback to arch code if there's nosmp or maxcpus=0 on the
  13180. * boot command line:
  13181. diff -Nur linux-4.4.13.orig/include/linux/spinlock_api_smp.h linux-4.4.13/include/linux/spinlock_api_smp.h
  13182. --- linux-4.4.13.orig/include/linux/spinlock_api_smp.h 2016-06-08 03:14:51.000000000 +0200
  13183. +++ linux-4.4.13/include/linux/spinlock_api_smp.h 2016-06-22 21:55:08.038523867 +0200
  13184. @@ -189,6 +189,8 @@
  13185. return 0;
  13186. }
  13187. -#include <linux/rwlock_api_smp.h>
  13188. +#ifndef CONFIG_PREEMPT_RT_FULL
  13189. +# include <linux/rwlock_api_smp.h>
  13190. +#endif
  13191. #endif /* __LINUX_SPINLOCK_API_SMP_H */
  13192. diff -Nur linux-4.4.13.orig/include/linux/spinlock.h linux-4.4.13/include/linux/spinlock.h
  13193. --- linux-4.4.13.orig/include/linux/spinlock.h 2016-06-08 03:14:51.000000000 +0200
  13194. +++ linux-4.4.13/include/linux/spinlock.h 2016-06-22 21:55:08.038523867 +0200
  13195. @@ -271,7 +271,11 @@
  13196. #define raw_spin_can_lock(lock) (!raw_spin_is_locked(lock))
  13197. /* Include rwlock functions */
  13198. -#include <linux/rwlock.h>
  13199. +#ifdef CONFIG_PREEMPT_RT_FULL
  13200. +# include <linux/rwlock_rt.h>
  13201. +#else
  13202. +# include <linux/rwlock.h>
  13203. +#endif
  13204. /*
  13205. * Pull the _spin_*()/_read_*()/_write_*() functions/declarations:
  13206. @@ -282,6 +286,10 @@
  13207. # include <linux/spinlock_api_up.h>
  13208. #endif
  13209. +#ifdef CONFIG_PREEMPT_RT_FULL
  13210. +# include <linux/spinlock_rt.h>
  13211. +#else /* PREEMPT_RT_FULL */
  13212. +
  13213. /*
  13214. * Map the spin_lock functions to the raw variants for PREEMPT_RT=n
  13215. */
  13216. @@ -416,4 +424,6 @@
  13217. #define atomic_dec_and_lock(atomic, lock) \
  13218. __cond_lock(lock, _atomic_dec_and_lock(atomic, lock))
  13219. +#endif /* !PREEMPT_RT_FULL */
  13220. +
  13221. #endif /* __LINUX_SPINLOCK_H */
  13222. diff -Nur linux-4.4.13.orig/include/linux/spinlock_rt.h linux-4.4.13/include/linux/spinlock_rt.h
  13223. --- linux-4.4.13.orig/include/linux/spinlock_rt.h 1970-01-01 01:00:00.000000000 +0100
  13224. +++ linux-4.4.13/include/linux/spinlock_rt.h 2016-06-22 21:55:08.038523867 +0200
  13225. @@ -0,0 +1,163 @@
  13226. +#ifndef __LINUX_SPINLOCK_RT_H
  13227. +#define __LINUX_SPINLOCK_RT_H
  13228. +
  13229. +#ifndef __LINUX_SPINLOCK_H
  13230. +#error Do not include directly. Use spinlock.h
  13231. +#endif
  13232. +
  13233. +#include <linux/bug.h>
  13234. +
  13235. +extern void
  13236. +__rt_spin_lock_init(spinlock_t *lock, char *name, struct lock_class_key *key);
  13237. +
  13238. +#define spin_lock_init(slock) \
  13239. +do { \
  13240. + static struct lock_class_key __key; \
  13241. + \
  13242. + rt_mutex_init(&(slock)->lock); \
  13243. + __rt_spin_lock_init(slock, #slock, &__key); \
  13244. +} while (0)
  13245. +
  13246. +void __lockfunc rt_spin_lock__no_mg(spinlock_t *lock);
  13247. +void __lockfunc rt_spin_unlock__no_mg(spinlock_t *lock);
  13248. +int __lockfunc rt_spin_trylock__no_mg(spinlock_t *lock);
  13249. +
  13250. +extern void __lockfunc rt_spin_lock(spinlock_t *lock);
  13251. +extern unsigned long __lockfunc rt_spin_lock_trace_flags(spinlock_t *lock);
  13252. +extern void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass);
  13253. +extern void __lockfunc rt_spin_unlock(spinlock_t *lock);
  13254. +extern void __lockfunc rt_spin_unlock_wait(spinlock_t *lock);
  13255. +extern int __lockfunc rt_spin_trylock_irqsave(spinlock_t *lock, unsigned long *flags);
  13256. +extern int __lockfunc rt_spin_trylock_bh(spinlock_t *lock);
  13257. +extern int __lockfunc rt_spin_trylock(spinlock_t *lock);
  13258. +extern int atomic_dec_and_spin_lock(atomic_t *atomic, spinlock_t *lock);
  13259. +
  13260. +/*
  13261. + * lockdep-less calls, for derived types like rwlock:
  13262. + * (for trylock they can use rt_mutex_trylock() directly.
  13263. + */
  13264. +extern void __lockfunc __rt_spin_lock__no_mg(struct rt_mutex *lock);
  13265. +extern void __lockfunc __rt_spin_lock(struct rt_mutex *lock);
  13266. +extern void __lockfunc __rt_spin_unlock(struct rt_mutex *lock);
  13267. +extern int __lockfunc __rt_spin_trylock(struct rt_mutex *lock);
  13268. +
  13269. +#define spin_lock(lock) rt_spin_lock(lock)
  13270. +
  13271. +#define spin_lock_bh(lock) \
  13272. + do { \
  13273. + local_bh_disable(); \
  13274. + rt_spin_lock(lock); \
  13275. + } while (0)
  13276. +
  13277. +#define spin_lock_irq(lock) spin_lock(lock)
  13278. +
  13279. +#define spin_do_trylock(lock) __cond_lock(lock, rt_spin_trylock(lock))
  13280. +
  13281. +#define spin_trylock(lock) \
  13282. +({ \
  13283. + int __locked; \
  13284. + __locked = spin_do_trylock(lock); \
  13285. + __locked; \
  13286. +})
  13287. +
  13288. +#ifdef CONFIG_LOCKDEP
  13289. +# define spin_lock_nested(lock, subclass) \
  13290. + do { \
  13291. + rt_spin_lock_nested(lock, subclass); \
  13292. + } while (0)
  13293. +
  13294. +#define spin_lock_bh_nested(lock, subclass) \
  13295. + do { \
  13296. + local_bh_disable(); \
  13297. + rt_spin_lock_nested(lock, subclass); \
  13298. + } while (0)
  13299. +
  13300. +# define spin_lock_irqsave_nested(lock, flags, subclass) \
  13301. + do { \
  13302. + typecheck(unsigned long, flags); \
  13303. + flags = 0; \
  13304. + rt_spin_lock_nested(lock, subclass); \
  13305. + } while (0)
  13306. +#else
  13307. +# define spin_lock_nested(lock, subclass) spin_lock(lock)
  13308. +# define spin_lock_bh_nested(lock, subclass) spin_lock_bh(lock)
  13309. +
  13310. +# define spin_lock_irqsave_nested(lock, flags, subclass) \
  13311. + do { \
  13312. + typecheck(unsigned long, flags); \
  13313. + flags = 0; \
  13314. + spin_lock(lock); \
  13315. + } while (0)
  13316. +#endif
  13317. +
  13318. +#define spin_lock_irqsave(lock, flags) \
  13319. + do { \
  13320. + typecheck(unsigned long, flags); \
  13321. + flags = 0; \
  13322. + spin_lock(lock); \
  13323. + } while (0)
  13324. +
  13325. +static inline unsigned long spin_lock_trace_flags(spinlock_t *lock)
  13326. +{
  13327. + unsigned long flags = 0;
  13328. +#ifdef CONFIG_TRACE_IRQFLAGS
  13329. + flags = rt_spin_lock_trace_flags(lock);
  13330. +#else
  13331. + spin_lock(lock); /* lock_local */
  13332. +#endif
  13333. + return flags;
  13334. +}
  13335. +
  13336. +/* FIXME: we need rt_spin_lock_nest_lock */
  13337. +#define spin_lock_nest_lock(lock, nest_lock) spin_lock_nested(lock, 0)
  13338. +
  13339. +#define spin_unlock(lock) rt_spin_unlock(lock)
  13340. +
  13341. +#define spin_unlock_bh(lock) \
  13342. + do { \
  13343. + rt_spin_unlock(lock); \
  13344. + local_bh_enable(); \
  13345. + } while (0)
  13346. +
  13347. +#define spin_unlock_irq(lock) spin_unlock(lock)
  13348. +
  13349. +#define spin_unlock_irqrestore(lock, flags) \
  13350. + do { \
  13351. + typecheck(unsigned long, flags); \
  13352. + (void) flags; \
  13353. + spin_unlock(lock); \
  13354. + } while (0)
  13355. +
  13356. +#define spin_trylock_bh(lock) __cond_lock(lock, rt_spin_trylock_bh(lock))
  13357. +#define spin_trylock_irq(lock) spin_trylock(lock)
  13358. +
  13359. +#define spin_trylock_irqsave(lock, flags) \
  13360. + rt_spin_trylock_irqsave(lock, &(flags))
  13361. +
  13362. +#define spin_unlock_wait(lock) rt_spin_unlock_wait(lock)
  13363. +
  13364. +#ifdef CONFIG_GENERIC_LOCKBREAK
  13365. +# define spin_is_contended(lock) ((lock)->break_lock)
  13366. +#else
  13367. +# define spin_is_contended(lock) (((void)(lock), 0))
  13368. +#endif
  13369. +
  13370. +static inline int spin_can_lock(spinlock_t *lock)
  13371. +{
  13372. + return !rt_mutex_is_locked(&lock->lock);
  13373. +}
  13374. +
  13375. +static inline int spin_is_locked(spinlock_t *lock)
  13376. +{
  13377. + return rt_mutex_is_locked(&lock->lock);
  13378. +}
  13379. +
  13380. +static inline void assert_spin_locked(spinlock_t *lock)
  13381. +{
  13382. + BUG_ON(!spin_is_locked(lock));
  13383. +}
  13384. +
  13385. +#define atomic_dec_and_lock(atomic, lock) \
  13386. + atomic_dec_and_spin_lock(atomic, lock)
  13387. +
  13388. +#endif
  13389. diff -Nur linux-4.4.13.orig/include/linux/spinlock_types.h linux-4.4.13/include/linux/spinlock_types.h
  13390. --- linux-4.4.13.orig/include/linux/spinlock_types.h 2016-06-08 03:14:51.000000000 +0200
  13391. +++ linux-4.4.13/include/linux/spinlock_types.h 2016-06-22 21:55:08.038523867 +0200
  13392. @@ -9,80 +9,15 @@
  13393. * Released under the General Public License (GPL).
  13394. */
  13395. -#if defined(CONFIG_SMP)
  13396. -# include <asm/spinlock_types.h>
  13397. -#else
  13398. -# include <linux/spinlock_types_up.h>
  13399. -#endif
  13400. -
  13401. -#include <linux/lockdep.h>
  13402. -
  13403. -typedef struct raw_spinlock {
  13404. - arch_spinlock_t raw_lock;
  13405. -#ifdef CONFIG_GENERIC_LOCKBREAK
  13406. - unsigned int break_lock;
  13407. -#endif
  13408. -#ifdef CONFIG_DEBUG_SPINLOCK
  13409. - unsigned int magic, owner_cpu;
  13410. - void *owner;
  13411. -#endif
  13412. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  13413. - struct lockdep_map dep_map;
  13414. -#endif
  13415. -} raw_spinlock_t;
  13416. -
  13417. -#define SPINLOCK_MAGIC 0xdead4ead
  13418. -
  13419. -#define SPINLOCK_OWNER_INIT ((void *)-1L)
  13420. -
  13421. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  13422. -# define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  13423. -#else
  13424. -# define SPIN_DEP_MAP_INIT(lockname)
  13425. -#endif
  13426. +#include <linux/spinlock_types_raw.h>
  13427. -#ifdef CONFIG_DEBUG_SPINLOCK
  13428. -# define SPIN_DEBUG_INIT(lockname) \
  13429. - .magic = SPINLOCK_MAGIC, \
  13430. - .owner_cpu = -1, \
  13431. - .owner = SPINLOCK_OWNER_INIT,
  13432. +#ifndef CONFIG_PREEMPT_RT_FULL
  13433. +# include <linux/spinlock_types_nort.h>
  13434. +# include <linux/rwlock_types.h>
  13435. #else
  13436. -# define SPIN_DEBUG_INIT(lockname)
  13437. +# include <linux/rtmutex.h>
  13438. +# include <linux/spinlock_types_rt.h>
  13439. +# include <linux/rwlock_types_rt.h>
  13440. #endif
  13441. -#define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
  13442. - { \
  13443. - .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
  13444. - SPIN_DEBUG_INIT(lockname) \
  13445. - SPIN_DEP_MAP_INIT(lockname) }
  13446. -
  13447. -#define __RAW_SPIN_LOCK_UNLOCKED(lockname) \
  13448. - (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
  13449. -
  13450. -#define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
  13451. -
  13452. -typedef struct spinlock {
  13453. - union {
  13454. - struct raw_spinlock rlock;
  13455. -
  13456. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  13457. -# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
  13458. - struct {
  13459. - u8 __padding[LOCK_PADSIZE];
  13460. - struct lockdep_map dep_map;
  13461. - };
  13462. -#endif
  13463. - };
  13464. -} spinlock_t;
  13465. -
  13466. -#define __SPIN_LOCK_INITIALIZER(lockname) \
  13467. - { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }
  13468. -
  13469. -#define __SPIN_LOCK_UNLOCKED(lockname) \
  13470. - (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)
  13471. -
  13472. -#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
  13473. -
  13474. -#include <linux/rwlock_types.h>
  13475. -
  13476. #endif /* __LINUX_SPINLOCK_TYPES_H */
  13477. diff -Nur linux-4.4.13.orig/include/linux/spinlock_types_nort.h linux-4.4.13/include/linux/spinlock_types_nort.h
  13478. --- linux-4.4.13.orig/include/linux/spinlock_types_nort.h 1970-01-01 01:00:00.000000000 +0100
  13479. +++ linux-4.4.13/include/linux/spinlock_types_nort.h 2016-06-22 21:55:08.038523867 +0200
  13480. @@ -0,0 +1,33 @@
  13481. +#ifndef __LINUX_SPINLOCK_TYPES_NORT_H
  13482. +#define __LINUX_SPINLOCK_TYPES_NORT_H
  13483. +
  13484. +#ifndef __LINUX_SPINLOCK_TYPES_H
  13485. +#error "Do not include directly. Include spinlock_types.h instead"
  13486. +#endif
  13487. +
  13488. +/*
  13489. + * The non RT version maps spinlocks to raw_spinlocks
  13490. + */
  13491. +typedef struct spinlock {
  13492. + union {
  13493. + struct raw_spinlock rlock;
  13494. +
  13495. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  13496. +# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
  13497. + struct {
  13498. + u8 __padding[LOCK_PADSIZE];
  13499. + struct lockdep_map dep_map;
  13500. + };
  13501. +#endif
  13502. + };
  13503. +} spinlock_t;
  13504. +
  13505. +#define __SPIN_LOCK_INITIALIZER(lockname) \
  13506. + { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }
  13507. +
  13508. +#define __SPIN_LOCK_UNLOCKED(lockname) \
  13509. + (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)
  13510. +
  13511. +#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
  13512. +
  13513. +#endif
  13514. diff -Nur linux-4.4.13.orig/include/linux/spinlock_types_raw.h linux-4.4.13/include/linux/spinlock_types_raw.h
  13515. --- linux-4.4.13.orig/include/linux/spinlock_types_raw.h 1970-01-01 01:00:00.000000000 +0100
  13516. +++ linux-4.4.13/include/linux/spinlock_types_raw.h 2016-06-22 21:55:08.038523867 +0200
  13517. @@ -0,0 +1,56 @@
  13518. +#ifndef __LINUX_SPINLOCK_TYPES_RAW_H
  13519. +#define __LINUX_SPINLOCK_TYPES_RAW_H
  13520. +
  13521. +#if defined(CONFIG_SMP)
  13522. +# include <asm/spinlock_types.h>
  13523. +#else
  13524. +# include <linux/spinlock_types_up.h>
  13525. +#endif
  13526. +
  13527. +#include <linux/lockdep.h>
  13528. +
  13529. +typedef struct raw_spinlock {
  13530. + arch_spinlock_t raw_lock;
  13531. +#ifdef CONFIG_GENERIC_LOCKBREAK
  13532. + unsigned int break_lock;
  13533. +#endif
  13534. +#ifdef CONFIG_DEBUG_SPINLOCK
  13535. + unsigned int magic, owner_cpu;
  13536. + void *owner;
  13537. +#endif
  13538. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  13539. + struct lockdep_map dep_map;
  13540. +#endif
  13541. +} raw_spinlock_t;
  13542. +
  13543. +#define SPINLOCK_MAGIC 0xdead4ead
  13544. +
  13545. +#define SPINLOCK_OWNER_INIT ((void *)-1L)
  13546. +
  13547. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  13548. +# define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  13549. +#else
  13550. +# define SPIN_DEP_MAP_INIT(lockname)
  13551. +#endif
  13552. +
  13553. +#ifdef CONFIG_DEBUG_SPINLOCK
  13554. +# define SPIN_DEBUG_INIT(lockname) \
  13555. + .magic = SPINLOCK_MAGIC, \
  13556. + .owner_cpu = -1, \
  13557. + .owner = SPINLOCK_OWNER_INIT,
  13558. +#else
  13559. +# define SPIN_DEBUG_INIT(lockname)
  13560. +#endif
  13561. +
  13562. +#define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
  13563. + { \
  13564. + .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
  13565. + SPIN_DEBUG_INIT(lockname) \
  13566. + SPIN_DEP_MAP_INIT(lockname) }
  13567. +
  13568. +#define __RAW_SPIN_LOCK_UNLOCKED(lockname) \
  13569. + (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
  13570. +
  13571. +#define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
  13572. +
  13573. +#endif
  13574. diff -Nur linux-4.4.13.orig/include/linux/spinlock_types_rt.h linux-4.4.13/include/linux/spinlock_types_rt.h
  13575. --- linux-4.4.13.orig/include/linux/spinlock_types_rt.h 1970-01-01 01:00:00.000000000 +0100
  13576. +++ linux-4.4.13/include/linux/spinlock_types_rt.h 2016-06-22 21:55:08.038523867 +0200
  13577. @@ -0,0 +1,51 @@
  13578. +#ifndef __LINUX_SPINLOCK_TYPES_RT_H
  13579. +#define __LINUX_SPINLOCK_TYPES_RT_H
  13580. +
  13581. +#ifndef __LINUX_SPINLOCK_TYPES_H
  13582. +#error "Do not include directly. Include spinlock_types.h instead"
  13583. +#endif
  13584. +
  13585. +#include <linux/cache.h>
  13586. +
  13587. +/*
  13588. + * PREEMPT_RT: spinlocks - an RT mutex plus lock-break field:
  13589. + */
  13590. +typedef struct spinlock {
  13591. + struct rt_mutex lock;
  13592. + unsigned int break_lock;
  13593. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  13594. + struct lockdep_map dep_map;
  13595. +#endif
  13596. +} spinlock_t;
  13597. +
  13598. +#ifdef CONFIG_DEBUG_RT_MUTEXES
  13599. +# define __RT_SPIN_INITIALIZER(name) \
  13600. + { \
  13601. + .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
  13602. + .save_state = 1, \
  13603. + .file = __FILE__, \
  13604. + .line = __LINE__ , \
  13605. + }
  13606. +#else
  13607. +# define __RT_SPIN_INITIALIZER(name) \
  13608. + { \
  13609. + .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
  13610. + .save_state = 1, \
  13611. + }
  13612. +#endif
  13613. +
  13614. +/*
  13615. +.wait_list = PLIST_HEAD_INIT_RAW((name).lock.wait_list, (name).lock.wait_lock)
  13616. +*/
  13617. +
  13618. +#define __SPIN_LOCK_UNLOCKED(name) \
  13619. + { .lock = __RT_SPIN_INITIALIZER(name.lock), \
  13620. + SPIN_DEP_MAP_INIT(name) }
  13621. +
  13622. +#define __DEFINE_SPINLOCK(name) \
  13623. + spinlock_t name = __SPIN_LOCK_UNLOCKED(name)
  13624. +
  13625. +#define DEFINE_SPINLOCK(name) \
  13626. + spinlock_t name __cacheline_aligned_in_smp = __SPIN_LOCK_UNLOCKED(name)
  13627. +
  13628. +#endif
  13629. diff -Nur linux-4.4.13.orig/include/linux/srcu.h linux-4.4.13/include/linux/srcu.h
  13630. --- linux-4.4.13.orig/include/linux/srcu.h 2016-06-08 03:14:51.000000000 +0200
  13631. +++ linux-4.4.13/include/linux/srcu.h 2016-06-22 21:55:08.038523867 +0200
  13632. @@ -84,10 +84,10 @@
  13633. void process_srcu(struct work_struct *work);
  13634. -#define __SRCU_STRUCT_INIT(name) \
  13635. +#define __SRCU_STRUCT_INIT(name, pcpu_name) \
  13636. { \
  13637. .completed = -300, \
  13638. - .per_cpu_ref = &name##_srcu_array, \
  13639. + .per_cpu_ref = &pcpu_name, \
  13640. .queue_lock = __SPIN_LOCK_UNLOCKED(name.queue_lock), \
  13641. .running = false, \
  13642. .batch_queue = RCU_BATCH_INIT(name.batch_queue), \
  13643. @@ -104,7 +104,7 @@
  13644. */
  13645. #define __DEFINE_SRCU(name, is_static) \
  13646. static DEFINE_PER_CPU(struct srcu_struct_array, name##_srcu_array);\
  13647. - is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name)
  13648. + is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name##_srcu_array)
  13649. #define DEFINE_SRCU(name) __DEFINE_SRCU(name, /* not static */)
  13650. #define DEFINE_STATIC_SRCU(name) __DEFINE_SRCU(name, static)
  13651. diff -Nur linux-4.4.13.orig/include/linux/suspend.h linux-4.4.13/include/linux/suspend.h
  13652. --- linux-4.4.13.orig/include/linux/suspend.h 2016-06-08 03:14:51.000000000 +0200
  13653. +++ linux-4.4.13/include/linux/suspend.h 2016-06-22 21:55:08.038523867 +0200
  13654. @@ -194,6 +194,12 @@
  13655. void (*end)(void);
  13656. };
  13657. +#if defined(CONFIG_SUSPEND) || defined(CONFIG_HIBERNATION)
  13658. +extern bool pm_in_action;
  13659. +#else
  13660. +# define pm_in_action false
  13661. +#endif
  13662. +
  13663. #ifdef CONFIG_SUSPEND
  13664. /**
  13665. * suspend_set_ops - set platform dependent suspend operations
  13666. diff -Nur linux-4.4.13.orig/include/linux/swait.h linux-4.4.13/include/linux/swait.h
  13667. --- linux-4.4.13.orig/include/linux/swait.h 1970-01-01 01:00:00.000000000 +0100
  13668. +++ linux-4.4.13/include/linux/swait.h 2016-06-22 21:55:08.038523867 +0200
  13669. @@ -0,0 +1,173 @@
  13670. +#ifndef _LINUX_SWAIT_H
  13671. +#define _LINUX_SWAIT_H
  13672. +
  13673. +#include <linux/list.h>
  13674. +#include <linux/stddef.h>
  13675. +#include <linux/spinlock.h>
  13676. +#include <asm/current.h>
  13677. +
  13678. +/*
  13679. + * Simple wait queues
  13680. + *
  13681. + * While these are very similar to the other/complex wait queues (wait.h) the
  13682. + * most important difference is that the simple waitqueue allows for
  13683. + * deterministic behaviour -- IOW it has strictly bounded IRQ and lock hold
  13684. + * times.
  13685. + *
  13686. + * In order to make this so, we had to drop a fair number of features of the
  13687. + * other waitqueue code; notably:
  13688. + *
  13689. + * - mixing INTERRUPTIBLE and UNINTERRUPTIBLE sleeps on the same waitqueue;
  13690. + * all wakeups are TASK_NORMAL in order to avoid O(n) lookups for the right
  13691. + * sleeper state.
  13692. + *
  13693. + * - the exclusive mode; because this requires preserving the list order
  13694. + * and this is hard.
  13695. + *
  13696. + * - custom wake functions; because you cannot give any guarantees about
  13697. + * random code.
  13698. + *
  13699. + * As a side effect of this; the data structures are slimmer.
  13700. + *
  13701. + * One would recommend using this wait queue where possible.
  13702. + */
  13703. +
  13704. +struct task_struct;
  13705. +
  13706. +struct swait_queue_head {
  13707. + raw_spinlock_t lock;
  13708. + struct list_head task_list;
  13709. +};
  13710. +
  13711. +struct swait_queue {
  13712. + struct task_struct *task;
  13713. + struct list_head task_list;
  13714. +};
  13715. +
  13716. +#define __SWAITQUEUE_INITIALIZER(name) { \
  13717. + .task = current, \
  13718. + .task_list = LIST_HEAD_INIT((name).task_list), \
  13719. +}
  13720. +
  13721. +#define DECLARE_SWAITQUEUE(name) \
  13722. + struct swait_queue name = __SWAITQUEUE_INITIALIZER(name)
  13723. +
  13724. +#define __SWAIT_QUEUE_HEAD_INITIALIZER(name) { \
  13725. + .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
  13726. + .task_list = LIST_HEAD_INIT((name).task_list), \
  13727. +}
  13728. +
  13729. +#define DECLARE_SWAIT_QUEUE_HEAD(name) \
  13730. + struct swait_queue_head name = __SWAIT_QUEUE_HEAD_INITIALIZER(name)
  13731. +
  13732. +extern void __init_swait_queue_head(struct swait_queue_head *q, const char *name,
  13733. + struct lock_class_key *key);
  13734. +
  13735. +#define init_swait_queue_head(q) \
  13736. + do { \
  13737. + static struct lock_class_key __key; \
  13738. + __init_swait_queue_head((q), #q, &__key); \
  13739. + } while (0)
  13740. +
  13741. +#ifdef CONFIG_LOCKDEP
  13742. +# define __SWAIT_QUEUE_HEAD_INIT_ONSTACK(name) \
  13743. + ({ init_swait_queue_head(&name); name; })
  13744. +# define DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(name) \
  13745. + struct swait_queue_head name = __SWAIT_QUEUE_HEAD_INIT_ONSTACK(name)
  13746. +#else
  13747. +# define DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(name) \
  13748. + DECLARE_SWAIT_QUEUE_HEAD(name)
  13749. +#endif
  13750. +
  13751. +static inline int swait_active(struct swait_queue_head *q)
  13752. +{
  13753. + return !list_empty(&q->task_list);
  13754. +}
  13755. +
  13756. +extern void swake_up(struct swait_queue_head *q);
  13757. +extern void swake_up_all(struct swait_queue_head *q);
  13758. +extern void swake_up_locked(struct swait_queue_head *q);
  13759. +extern void swake_up_all_locked(struct swait_queue_head *q);
  13760. +
  13761. +extern void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait);
  13762. +extern void prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait, int state);
  13763. +extern long prepare_to_swait_event(struct swait_queue_head *q, struct swait_queue *wait, int state);
  13764. +
  13765. +extern void __finish_swait(struct swait_queue_head *q, struct swait_queue *wait);
  13766. +extern void finish_swait(struct swait_queue_head *q, struct swait_queue *wait);
  13767. +
  13768. +/* as per ___wait_event() but for swait, therefore "exclusive == 0" */
  13769. +#define ___swait_event(wq, condition, state, ret, cmd) \
  13770. +({ \
  13771. + struct swait_queue __wait; \
  13772. + long __ret = ret; \
  13773. + \
  13774. + INIT_LIST_HEAD(&__wait.task_list); \
  13775. + for (;;) { \
  13776. + long __int = prepare_to_swait_event(&wq, &__wait, state);\
  13777. + \
  13778. + if (condition) \
  13779. + break; \
  13780. + \
  13781. + if (___wait_is_interruptible(state) && __int) { \
  13782. + __ret = __int; \
  13783. + break; \
  13784. + } \
  13785. + \
  13786. + cmd; \
  13787. + } \
  13788. + finish_swait(&wq, &__wait); \
  13789. + __ret; \
  13790. +})
  13791. +
  13792. +#define __swait_event(wq, condition) \
  13793. + (void)___swait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, \
  13794. + schedule())
  13795. +
  13796. +#define swait_event(wq, condition) \
  13797. +do { \
  13798. + if (condition) \
  13799. + break; \
  13800. + __swait_event(wq, condition); \
  13801. +} while (0)
  13802. +
  13803. +#define __swait_event_timeout(wq, condition, timeout) \
  13804. + ___swait_event(wq, ___wait_cond_timeout(condition), \
  13805. + TASK_UNINTERRUPTIBLE, timeout, \
  13806. + __ret = schedule_timeout(__ret))
  13807. +
  13808. +#define swait_event_timeout(wq, condition, timeout) \
  13809. +({ \
  13810. + long __ret = timeout; \
  13811. + if (!___wait_cond_timeout(condition)) \
  13812. + __ret = __swait_event_timeout(wq, condition, timeout); \
  13813. + __ret; \
  13814. +})
  13815. +
  13816. +#define __swait_event_interruptible(wq, condition) \
  13817. + ___swait_event(wq, condition, TASK_INTERRUPTIBLE, 0, \
  13818. + schedule())
  13819. +
  13820. +#define swait_event_interruptible(wq, condition) \
  13821. +({ \
  13822. + int __ret = 0; \
  13823. + if (!(condition)) \
  13824. + __ret = __swait_event_interruptible(wq, condition); \
  13825. + __ret; \
  13826. +})
  13827. +
  13828. +#define __swait_event_interruptible_timeout(wq, condition, timeout) \
  13829. + ___swait_event(wq, ___wait_cond_timeout(condition), \
  13830. + TASK_INTERRUPTIBLE, timeout, \
  13831. + __ret = schedule_timeout(__ret))
  13832. +
  13833. +#define swait_event_interruptible_timeout(wq, condition, timeout) \
  13834. +({ \
  13835. + long __ret = timeout; \
  13836. + if (!___wait_cond_timeout(condition)) \
  13837. + __ret = __swait_event_interruptible_timeout(wq, \
  13838. + condition, timeout); \
  13839. + __ret; \
  13840. +})
  13841. +
  13842. +#endif /* _LINUX_SWAIT_H */
  13843. diff -Nur linux-4.4.13.orig/include/linux/swap.h linux-4.4.13/include/linux/swap.h
  13844. --- linux-4.4.13.orig/include/linux/swap.h 2016-06-08 03:14:51.000000000 +0200
  13845. +++ linux-4.4.13/include/linux/swap.h 2016-06-22 21:55:08.038523867 +0200
  13846. @@ -11,6 +11,7 @@
  13847. #include <linux/fs.h>
  13848. #include <linux/atomic.h>
  13849. #include <linux/page-flags.h>
  13850. +#include <linux/locallock.h>
  13851. #include <asm/page.h>
  13852. struct notifier_block;
  13853. @@ -252,7 +253,8 @@
  13854. void *workingset_eviction(struct address_space *mapping, struct page *page);
  13855. bool workingset_refault(void *shadow);
  13856. void workingset_activation(struct page *page);
  13857. -extern struct list_lru workingset_shadow_nodes;
  13858. +extern struct list_lru __workingset_shadow_nodes;
  13859. +DECLARE_LOCAL_IRQ_LOCK(workingset_shadow_lock);
  13860. static inline unsigned int workingset_node_pages(struct radix_tree_node *node)
  13861. {
  13862. @@ -296,6 +298,7 @@
  13863. /* linux/mm/swap.c */
  13864. +DECLARE_LOCAL_IRQ_LOCK(swapvec_lock);
  13865. extern void lru_cache_add(struct page *);
  13866. extern void lru_cache_add_anon(struct page *page);
  13867. extern void lru_cache_add_file(struct page *page);
  13868. diff -Nur linux-4.4.13.orig/include/linux/thread_info.h linux-4.4.13/include/linux/thread_info.h
  13869. --- linux-4.4.13.orig/include/linux/thread_info.h 2016-06-08 03:14:51.000000000 +0200
  13870. +++ linux-4.4.13/include/linux/thread_info.h 2016-06-22 21:55:08.038523867 +0200
  13871. @@ -102,7 +102,17 @@
  13872. #define test_thread_flag(flag) \
  13873. test_ti_thread_flag(current_thread_info(), flag)
  13874. -#define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
  13875. +#ifdef CONFIG_PREEMPT_LAZY
  13876. +#define tif_need_resched() (test_thread_flag(TIF_NEED_RESCHED) || \
  13877. + test_thread_flag(TIF_NEED_RESCHED_LAZY))
  13878. +#define tif_need_resched_now() (test_thread_flag(TIF_NEED_RESCHED))
  13879. +#define tif_need_resched_lazy() test_thread_flag(TIF_NEED_RESCHED_LAZY))
  13880. +
  13881. +#else
  13882. +#define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
  13883. +#define tif_need_resched_now() test_thread_flag(TIF_NEED_RESCHED)
  13884. +#define tif_need_resched_lazy() 0
  13885. +#endif
  13886. #if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
  13887. /*
  13888. diff -Nur linux-4.4.13.orig/include/linux/timer.h linux-4.4.13/include/linux/timer.h
  13889. --- linux-4.4.13.orig/include/linux/timer.h 2016-06-08 03:14:51.000000000 +0200
  13890. +++ linux-4.4.13/include/linux/timer.h 2016-06-22 21:55:08.038523867 +0200
  13891. @@ -225,7 +225,7 @@
  13892. extern int try_to_del_timer_sync(struct timer_list *timer);
  13893. -#ifdef CONFIG_SMP
  13894. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  13895. extern int del_timer_sync(struct timer_list *timer);
  13896. #else
  13897. # define del_timer_sync(t) del_timer(t)
  13898. diff -Nur linux-4.4.13.orig/include/linux/trace_events.h linux-4.4.13/include/linux/trace_events.h
  13899. --- linux-4.4.13.orig/include/linux/trace_events.h 2016-06-08 03:14:51.000000000 +0200
  13900. +++ linux-4.4.13/include/linux/trace_events.h 2016-06-22 21:55:08.038523867 +0200
  13901. @@ -66,6 +66,9 @@
  13902. unsigned char flags;
  13903. unsigned char preempt_count;
  13904. int pid;
  13905. + unsigned short migrate_disable;
  13906. + unsigned short padding;
  13907. + unsigned char preempt_lazy_count;
  13908. };
  13909. #define TRACE_EVENT_TYPE_MAX \
  13910. diff -Nur linux-4.4.13.orig/include/linux/uaccess.h linux-4.4.13/include/linux/uaccess.h
  13911. --- linux-4.4.13.orig/include/linux/uaccess.h 2016-06-08 03:14:51.000000000 +0200
  13912. +++ linux-4.4.13/include/linux/uaccess.h 2016-06-22 21:55:08.038523867 +0200
  13913. @@ -24,6 +24,7 @@
  13914. */
  13915. static inline void pagefault_disable(void)
  13916. {
  13917. + migrate_disable();
  13918. pagefault_disabled_inc();
  13919. /*
  13920. * make sure to have issued the store before a pagefault
  13921. @@ -40,6 +41,7 @@
  13922. */
  13923. barrier();
  13924. pagefault_disabled_dec();
  13925. + migrate_enable();
  13926. }
  13927. /*
  13928. diff -Nur linux-4.4.13.orig/include/linux/uprobes.h linux-4.4.13/include/linux/uprobes.h
  13929. --- linux-4.4.13.orig/include/linux/uprobes.h 2016-06-08 03:14:51.000000000 +0200
  13930. +++ linux-4.4.13/include/linux/uprobes.h 2016-06-22 21:55:08.038523867 +0200
  13931. @@ -27,6 +27,7 @@
  13932. #include <linux/errno.h>
  13933. #include <linux/rbtree.h>
  13934. #include <linux/types.h>
  13935. +#include <linux/wait.h>
  13936. struct vm_area_struct;
  13937. struct mm_struct;
  13938. diff -Nur linux-4.4.13.orig/include/linux/vmstat.h linux-4.4.13/include/linux/vmstat.h
  13939. --- linux-4.4.13.orig/include/linux/vmstat.h 2016-06-08 03:14:51.000000000 +0200
  13940. +++ linux-4.4.13/include/linux/vmstat.h 2016-06-22 21:55:08.042523867 +0200
  13941. @@ -33,7 +33,9 @@
  13942. */
  13943. static inline void __count_vm_event(enum vm_event_item item)
  13944. {
  13945. + preempt_disable_rt();
  13946. raw_cpu_inc(vm_event_states.event[item]);
  13947. + preempt_enable_rt();
  13948. }
  13949. static inline void count_vm_event(enum vm_event_item item)
  13950. @@ -43,7 +45,9 @@
  13951. static inline void __count_vm_events(enum vm_event_item item, long delta)
  13952. {
  13953. + preempt_disable_rt();
  13954. raw_cpu_add(vm_event_states.event[item], delta);
  13955. + preempt_enable_rt();
  13956. }
  13957. static inline void count_vm_events(enum vm_event_item item, long delta)
  13958. diff -Nur linux-4.4.13.orig/include/linux/wait.h linux-4.4.13/include/linux/wait.h
  13959. --- linux-4.4.13.orig/include/linux/wait.h 2016-06-08 03:14:51.000000000 +0200
  13960. +++ linux-4.4.13/include/linux/wait.h 2016-06-22 21:55:08.042523867 +0200
  13961. @@ -8,6 +8,7 @@
  13962. #include <linux/spinlock.h>
  13963. #include <asm/current.h>
  13964. #include <uapi/linux/wait.h>
  13965. +#include <linux/atomic.h>
  13966. typedef struct __wait_queue wait_queue_t;
  13967. typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key);
  13968. diff -Nur linux-4.4.13.orig/include/linux/work-simple.h linux-4.4.13/include/linux/work-simple.h
  13969. --- linux-4.4.13.orig/include/linux/work-simple.h 1970-01-01 01:00:00.000000000 +0100
  13970. +++ linux-4.4.13/include/linux/work-simple.h 2016-06-22 21:55:08.042523867 +0200
  13971. @@ -0,0 +1,24 @@
  13972. +#ifndef _LINUX_SWORK_H
  13973. +#define _LINUX_SWORK_H
  13974. +
  13975. +#include <linux/list.h>
  13976. +
  13977. +struct swork_event {
  13978. + struct list_head item;
  13979. + unsigned long flags;
  13980. + void (*func)(struct swork_event *);
  13981. +};
  13982. +
  13983. +static inline void INIT_SWORK(struct swork_event *event,
  13984. + void (*func)(struct swork_event *))
  13985. +{
  13986. + event->flags = 0;
  13987. + event->func = func;
  13988. +}
  13989. +
  13990. +bool swork_queue(struct swork_event *sev);
  13991. +
  13992. +int swork_get(void);
  13993. +void swork_put(void);
  13994. +
  13995. +#endif /* _LINUX_SWORK_H */
  13996. diff -Nur linux-4.4.13.orig/include/net/dst.h linux-4.4.13/include/net/dst.h
  13997. --- linux-4.4.13.orig/include/net/dst.h 2016-06-08 03:14:51.000000000 +0200
  13998. +++ linux-4.4.13/include/net/dst.h 2016-06-22 21:55:08.042523867 +0200
  13999. @@ -437,7 +437,7 @@
  14000. static inline int dst_neigh_output(struct dst_entry *dst, struct neighbour *n,
  14001. struct sk_buff *skb)
  14002. {
  14003. - const struct hh_cache *hh;
  14004. + struct hh_cache *hh;
  14005. if (dst->pending_confirm) {
  14006. unsigned long now = jiffies;
  14007. diff -Nur linux-4.4.13.orig/include/net/neighbour.h linux-4.4.13/include/net/neighbour.h
  14008. --- linux-4.4.13.orig/include/net/neighbour.h 2016-06-08 03:14:51.000000000 +0200
  14009. +++ linux-4.4.13/include/net/neighbour.h 2016-06-22 21:55:08.042523867 +0200
  14010. @@ -446,7 +446,7 @@
  14011. }
  14012. #endif
  14013. -static inline int neigh_hh_output(const struct hh_cache *hh, struct sk_buff *skb)
  14014. +static inline int neigh_hh_output(struct hh_cache *hh, struct sk_buff *skb)
  14015. {
  14016. unsigned int seq;
  14017. int hh_len;
  14018. @@ -501,7 +501,7 @@
  14019. #define NEIGH_CB(skb) ((struct neighbour_cb *)(skb)->cb)
  14020. -static inline void neigh_ha_snapshot(char *dst, const struct neighbour *n,
  14021. +static inline void neigh_ha_snapshot(char *dst, struct neighbour *n,
  14022. const struct net_device *dev)
  14023. {
  14024. unsigned int seq;
  14025. diff -Nur linux-4.4.13.orig/include/net/netns/ipv4.h linux-4.4.13/include/net/netns/ipv4.h
  14026. --- linux-4.4.13.orig/include/net/netns/ipv4.h 2016-06-08 03:14:51.000000000 +0200
  14027. +++ linux-4.4.13/include/net/netns/ipv4.h 2016-06-22 21:55:08.042523867 +0200
  14028. @@ -70,6 +70,7 @@
  14029. int sysctl_icmp_echo_ignore_all;
  14030. int sysctl_icmp_echo_ignore_broadcasts;
  14031. + int sysctl_icmp_echo_sysrq;
  14032. int sysctl_icmp_ignore_bogus_error_responses;
  14033. int sysctl_icmp_ratelimit;
  14034. int sysctl_icmp_ratemask;
  14035. diff -Nur linux-4.4.13.orig/include/trace/events/hist.h linux-4.4.13/include/trace/events/hist.h
  14036. --- linux-4.4.13.orig/include/trace/events/hist.h 1970-01-01 01:00:00.000000000 +0100
  14037. +++ linux-4.4.13/include/trace/events/hist.h 2016-06-22 21:55:08.042523867 +0200
  14038. @@ -0,0 +1,73 @@
  14039. +#undef TRACE_SYSTEM
  14040. +#define TRACE_SYSTEM hist
  14041. +
  14042. +#if !defined(_TRACE_HIST_H) || defined(TRACE_HEADER_MULTI_READ)
  14043. +#define _TRACE_HIST_H
  14044. +
  14045. +#include "latency_hist.h"
  14046. +#include <linux/tracepoint.h>
  14047. +
  14048. +#if !defined(CONFIG_PREEMPT_OFF_HIST) && !defined(CONFIG_INTERRUPT_OFF_HIST)
  14049. +#define trace_preemptirqsoff_hist(a, b)
  14050. +#define trace_preemptirqsoff_hist_rcuidle(a, b)
  14051. +#else
  14052. +TRACE_EVENT(preemptirqsoff_hist,
  14053. +
  14054. + TP_PROTO(int reason, int starthist),
  14055. +
  14056. + TP_ARGS(reason, starthist),
  14057. +
  14058. + TP_STRUCT__entry(
  14059. + __field(int, reason)
  14060. + __field(int, starthist)
  14061. + ),
  14062. +
  14063. + TP_fast_assign(
  14064. + __entry->reason = reason;
  14065. + __entry->starthist = starthist;
  14066. + ),
  14067. +
  14068. + TP_printk("reason=%s starthist=%s", getaction(__entry->reason),
  14069. + __entry->starthist ? "start" : "stop")
  14070. +);
  14071. +#endif
  14072. +
  14073. +#ifndef CONFIG_MISSED_TIMER_OFFSETS_HIST
  14074. +#define trace_hrtimer_interrupt(a, b, c, d)
  14075. +#else
  14076. +TRACE_EVENT(hrtimer_interrupt,
  14077. +
  14078. + TP_PROTO(int cpu, long long offset, struct task_struct *curr,
  14079. + struct task_struct *task),
  14080. +
  14081. + TP_ARGS(cpu, offset, curr, task),
  14082. +
  14083. + TP_STRUCT__entry(
  14084. + __field(int, cpu)
  14085. + __field(long long, offset)
  14086. + __array(char, ccomm, TASK_COMM_LEN)
  14087. + __field(int, cprio)
  14088. + __array(char, tcomm, TASK_COMM_LEN)
  14089. + __field(int, tprio)
  14090. + ),
  14091. +
  14092. + TP_fast_assign(
  14093. + __entry->cpu = cpu;
  14094. + __entry->offset = offset;
  14095. + memcpy(__entry->ccomm, curr->comm, TASK_COMM_LEN);
  14096. + __entry->cprio = curr->prio;
  14097. + memcpy(__entry->tcomm, task != NULL ? task->comm : "<none>",
  14098. + task != NULL ? TASK_COMM_LEN : 7);
  14099. + __entry->tprio = task != NULL ? task->prio : -1;
  14100. + ),
  14101. +
  14102. + TP_printk("cpu=%d offset=%lld curr=%s[%d] thread=%s[%d]",
  14103. + __entry->cpu, __entry->offset, __entry->ccomm,
  14104. + __entry->cprio, __entry->tcomm, __entry->tprio)
  14105. +);
  14106. +#endif
  14107. +
  14108. +#endif /* _TRACE_HIST_H */
  14109. +
  14110. +/* This part must be outside protection */
  14111. +#include <trace/define_trace.h>
  14112. diff -Nur linux-4.4.13.orig/include/trace/events/latency_hist.h linux-4.4.13/include/trace/events/latency_hist.h
  14113. --- linux-4.4.13.orig/include/trace/events/latency_hist.h 1970-01-01 01:00:00.000000000 +0100
  14114. +++ linux-4.4.13/include/trace/events/latency_hist.h 2016-06-22 21:55:08.042523867 +0200
  14115. @@ -0,0 +1,29 @@
  14116. +#ifndef _LATENCY_HIST_H
  14117. +#define _LATENCY_HIST_H
  14118. +
  14119. +enum hist_action {
  14120. + IRQS_ON,
  14121. + PREEMPT_ON,
  14122. + TRACE_STOP,
  14123. + IRQS_OFF,
  14124. + PREEMPT_OFF,
  14125. + TRACE_START,
  14126. +};
  14127. +
  14128. +static char *actions[] = {
  14129. + "IRQS_ON",
  14130. + "PREEMPT_ON",
  14131. + "TRACE_STOP",
  14132. + "IRQS_OFF",
  14133. + "PREEMPT_OFF",
  14134. + "TRACE_START",
  14135. +};
  14136. +
  14137. +static inline char *getaction(int action)
  14138. +{
  14139. + if (action >= 0 && action <= sizeof(actions)/sizeof(actions[0]))
  14140. + return actions[action];
  14141. + return "unknown";
  14142. +}
  14143. +
  14144. +#endif /* _LATENCY_HIST_H */
  14145. diff -Nur linux-4.4.13.orig/include/trace/events/writeback.h linux-4.4.13/include/trace/events/writeback.h
  14146. --- linux-4.4.13.orig/include/trace/events/writeback.h 2016-06-08 03:14:51.000000000 +0200
  14147. +++ linux-4.4.13/include/trace/events/writeback.h 2016-06-22 21:55:08.042523867 +0200
  14148. @@ -134,58 +134,28 @@
  14149. #ifdef CREATE_TRACE_POINTS
  14150. #ifdef CONFIG_CGROUP_WRITEBACK
  14151. -static inline size_t __trace_wb_cgroup_size(struct bdi_writeback *wb)
  14152. +static inline unsigned int __trace_wb_assign_cgroup(struct bdi_writeback *wb)
  14153. {
  14154. - return kernfs_path_len(wb->memcg_css->cgroup->kn) + 1;
  14155. + return wb->memcg_css->cgroup->kn->ino;
  14156. }
  14157. -static inline void __trace_wb_assign_cgroup(char *buf, struct bdi_writeback *wb)
  14158. -{
  14159. - struct cgroup *cgrp = wb->memcg_css->cgroup;
  14160. - char *path;
  14161. -
  14162. - path = cgroup_path(cgrp, buf, kernfs_path_len(cgrp->kn) + 1);
  14163. - WARN_ON_ONCE(path != buf);
  14164. -}
  14165. -
  14166. -static inline size_t __trace_wbc_cgroup_size(struct writeback_control *wbc)
  14167. -{
  14168. - if (wbc->wb)
  14169. - return __trace_wb_cgroup_size(wbc->wb);
  14170. - else
  14171. - return 2;
  14172. -}
  14173. -
  14174. -static inline void __trace_wbc_assign_cgroup(char *buf,
  14175. - struct writeback_control *wbc)
  14176. +static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *wbc)
  14177. {
  14178. if (wbc->wb)
  14179. - __trace_wb_assign_cgroup(buf, wbc->wb);
  14180. + return __trace_wb_assign_cgroup(wbc->wb);
  14181. else
  14182. - strcpy(buf, "/");
  14183. + return -1U;
  14184. }
  14185. -
  14186. #else /* CONFIG_CGROUP_WRITEBACK */
  14187. -static inline size_t __trace_wb_cgroup_size(struct bdi_writeback *wb)
  14188. -{
  14189. - return 2;
  14190. -}
  14191. -
  14192. -static inline void __trace_wb_assign_cgroup(char *buf, struct bdi_writeback *wb)
  14193. -{
  14194. - strcpy(buf, "/");
  14195. -}
  14196. -
  14197. -static inline size_t __trace_wbc_cgroup_size(struct writeback_control *wbc)
  14198. +static inline unsigned int __trace_wb_assign_cgroup(struct bdi_writeback *wb)
  14199. {
  14200. - return 2;
  14201. + return -1U;
  14202. }
  14203. -static inline void __trace_wbc_assign_cgroup(char *buf,
  14204. - struct writeback_control *wbc)
  14205. +static inline unsigned int __trace_wbc_assign_cgroup(struct writeback_control *wbc)
  14206. {
  14207. - strcpy(buf, "/");
  14208. + return -1U;
  14209. }
  14210. #endif /* CONFIG_CGROUP_WRITEBACK */
  14211. @@ -201,7 +171,7 @@
  14212. __array(char, name, 32)
  14213. __field(unsigned long, ino)
  14214. __field(int, sync_mode)
  14215. - __dynamic_array(char, cgroup, __trace_wbc_cgroup_size(wbc))
  14216. + __field(unsigned int, cgroup_ino)
  14217. ),
  14218. TP_fast_assign(
  14219. @@ -209,14 +179,14 @@
  14220. dev_name(inode_to_bdi(inode)->dev), 32);
  14221. __entry->ino = inode->i_ino;
  14222. __entry->sync_mode = wbc->sync_mode;
  14223. - __trace_wbc_assign_cgroup(__get_str(cgroup), wbc);
  14224. + __entry->cgroup_ino = __trace_wbc_assign_cgroup(wbc);
  14225. ),
  14226. - TP_printk("bdi %s: ino=%lu sync_mode=%d cgroup=%s",
  14227. + TP_printk("bdi %s: ino=%lu sync_mode=%d cgroup_ino=%u",
  14228. __entry->name,
  14229. __entry->ino,
  14230. __entry->sync_mode,
  14231. - __get_str(cgroup)
  14232. + __entry->cgroup_ino
  14233. )
  14234. );
  14235. @@ -246,7 +216,7 @@
  14236. __field(int, range_cyclic)
  14237. __field(int, for_background)
  14238. __field(int, reason)
  14239. - __dynamic_array(char, cgroup, __trace_wb_cgroup_size(wb))
  14240. + __field(unsigned int, cgroup_ino)
  14241. ),
  14242. TP_fast_assign(
  14243. strncpy(__entry->name,
  14244. @@ -258,10 +228,10 @@
  14245. __entry->range_cyclic = work->range_cyclic;
  14246. __entry->for_background = work->for_background;
  14247. __entry->reason = work->reason;
  14248. - __trace_wb_assign_cgroup(__get_str(cgroup), wb);
  14249. + __entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
  14250. ),
  14251. TP_printk("bdi %s: sb_dev %d:%d nr_pages=%ld sync_mode=%d "
  14252. - "kupdate=%d range_cyclic=%d background=%d reason=%s cgroup=%s",
  14253. + "kupdate=%d range_cyclic=%d background=%d reason=%s cgroup_ino=%u",
  14254. __entry->name,
  14255. MAJOR(__entry->sb_dev), MINOR(__entry->sb_dev),
  14256. __entry->nr_pages,
  14257. @@ -270,7 +240,7 @@
  14258. __entry->range_cyclic,
  14259. __entry->for_background,
  14260. __print_symbolic(__entry->reason, WB_WORK_REASON),
  14261. - __get_str(cgroup)
  14262. + __entry->cgroup_ino
  14263. )
  14264. );
  14265. #define DEFINE_WRITEBACK_WORK_EVENT(name) \
  14266. @@ -300,15 +270,15 @@
  14267. TP_ARGS(wb),
  14268. TP_STRUCT__entry(
  14269. __array(char, name, 32)
  14270. - __dynamic_array(char, cgroup, __trace_wb_cgroup_size(wb))
  14271. + __field(unsigned int, cgroup_ino)
  14272. ),
  14273. TP_fast_assign(
  14274. strncpy(__entry->name, dev_name(wb->bdi->dev), 32);
  14275. - __trace_wb_assign_cgroup(__get_str(cgroup), wb);
  14276. + __entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
  14277. ),
  14278. - TP_printk("bdi %s: cgroup=%s",
  14279. + TP_printk("bdi %s: cgroup_ino=%u",
  14280. __entry->name,
  14281. - __get_str(cgroup)
  14282. + __entry->cgroup_ino
  14283. )
  14284. );
  14285. #define DEFINE_WRITEBACK_EVENT(name) \
  14286. @@ -347,7 +317,7 @@
  14287. __field(int, range_cyclic)
  14288. __field(long, range_start)
  14289. __field(long, range_end)
  14290. - __dynamic_array(char, cgroup, __trace_wbc_cgroup_size(wbc))
  14291. + __field(unsigned int, cgroup_ino)
  14292. ),
  14293. TP_fast_assign(
  14294. @@ -361,12 +331,12 @@
  14295. __entry->range_cyclic = wbc->range_cyclic;
  14296. __entry->range_start = (long)wbc->range_start;
  14297. __entry->range_end = (long)wbc->range_end;
  14298. - __trace_wbc_assign_cgroup(__get_str(cgroup), wbc);
  14299. + __entry->cgroup_ino = __trace_wbc_assign_cgroup(wbc);
  14300. ),
  14301. TP_printk("bdi %s: towrt=%ld skip=%ld mode=%d kupd=%d "
  14302. "bgrd=%d reclm=%d cyclic=%d "
  14303. - "start=0x%lx end=0x%lx cgroup=%s",
  14304. + "start=0x%lx end=0x%lx cgroup_ino=%u",
  14305. __entry->name,
  14306. __entry->nr_to_write,
  14307. __entry->pages_skipped,
  14308. @@ -377,7 +347,7 @@
  14309. __entry->range_cyclic,
  14310. __entry->range_start,
  14311. __entry->range_end,
  14312. - __get_str(cgroup)
  14313. + __entry->cgroup_ino
  14314. )
  14315. )
  14316. @@ -398,7 +368,7 @@
  14317. __field(long, age)
  14318. __field(int, moved)
  14319. __field(int, reason)
  14320. - __dynamic_array(char, cgroup, __trace_wb_cgroup_size(wb))
  14321. + __field(unsigned int, cgroup_ino)
  14322. ),
  14323. TP_fast_assign(
  14324. unsigned long *older_than_this = work->older_than_this;
  14325. @@ -408,15 +378,15 @@
  14326. (jiffies - *older_than_this) * 1000 / HZ : -1;
  14327. __entry->moved = moved;
  14328. __entry->reason = work->reason;
  14329. - __trace_wb_assign_cgroup(__get_str(cgroup), wb);
  14330. + __entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
  14331. ),
  14332. - TP_printk("bdi %s: older=%lu age=%ld enqueue=%d reason=%s cgroup=%s",
  14333. + TP_printk("bdi %s: older=%lu age=%ld enqueue=%d reason=%s cgroup_ino=%u",
  14334. __entry->name,
  14335. __entry->older, /* older_than_this in jiffies */
  14336. __entry->age, /* older_than_this in relative milliseconds */
  14337. __entry->moved,
  14338. __print_symbolic(__entry->reason, WB_WORK_REASON),
  14339. - __get_str(cgroup)
  14340. + __entry->cgroup_ino
  14341. )
  14342. );
  14343. @@ -484,7 +454,7 @@
  14344. __field(unsigned long, dirty_ratelimit)
  14345. __field(unsigned long, task_ratelimit)
  14346. __field(unsigned long, balanced_dirty_ratelimit)
  14347. - __dynamic_array(char, cgroup, __trace_wb_cgroup_size(wb))
  14348. + __field(unsigned int, cgroup_ino)
  14349. ),
  14350. TP_fast_assign(
  14351. @@ -496,13 +466,13 @@
  14352. __entry->task_ratelimit = KBps(task_ratelimit);
  14353. __entry->balanced_dirty_ratelimit =
  14354. KBps(wb->balanced_dirty_ratelimit);
  14355. - __trace_wb_assign_cgroup(__get_str(cgroup), wb);
  14356. + __entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
  14357. ),
  14358. TP_printk("bdi %s: "
  14359. "write_bw=%lu awrite_bw=%lu dirty_rate=%lu "
  14360. "dirty_ratelimit=%lu task_ratelimit=%lu "
  14361. - "balanced_dirty_ratelimit=%lu cgroup=%s",
  14362. + "balanced_dirty_ratelimit=%lu cgroup_ino=%u",
  14363. __entry->bdi,
  14364. __entry->write_bw, /* write bandwidth */
  14365. __entry->avg_write_bw, /* avg write bandwidth */
  14366. @@ -510,7 +480,7 @@
  14367. __entry->dirty_ratelimit, /* base ratelimit */
  14368. __entry->task_ratelimit, /* ratelimit with position control */
  14369. __entry->balanced_dirty_ratelimit, /* the balanced ratelimit */
  14370. - __get_str(cgroup)
  14371. + __entry->cgroup_ino
  14372. )
  14373. );
  14374. @@ -548,7 +518,7 @@
  14375. __field( long, pause)
  14376. __field(unsigned long, period)
  14377. __field( long, think)
  14378. - __dynamic_array(char, cgroup, __trace_wb_cgroup_size(wb))
  14379. + __field(unsigned int, cgroup_ino)
  14380. ),
  14381. TP_fast_assign(
  14382. @@ -571,7 +541,7 @@
  14383. __entry->period = period * 1000 / HZ;
  14384. __entry->pause = pause * 1000 / HZ;
  14385. __entry->paused = (jiffies - start_time) * 1000 / HZ;
  14386. - __trace_wb_assign_cgroup(__get_str(cgroup), wb);
  14387. + __entry->cgroup_ino = __trace_wb_assign_cgroup(wb);
  14388. ),
  14389. @@ -580,7 +550,7 @@
  14390. "bdi_setpoint=%lu bdi_dirty=%lu "
  14391. "dirty_ratelimit=%lu task_ratelimit=%lu "
  14392. "dirtied=%u dirtied_pause=%u "
  14393. - "paused=%lu pause=%ld period=%lu think=%ld cgroup=%s",
  14394. + "paused=%lu pause=%ld period=%lu think=%ld cgroup_ino=%u",
  14395. __entry->bdi,
  14396. __entry->limit,
  14397. __entry->setpoint,
  14398. @@ -595,7 +565,7 @@
  14399. __entry->pause, /* ms */
  14400. __entry->period, /* ms */
  14401. __entry->think, /* ms */
  14402. - __get_str(cgroup)
  14403. + __entry->cgroup_ino
  14404. )
  14405. );
  14406. @@ -609,8 +579,7 @@
  14407. __field(unsigned long, ino)
  14408. __field(unsigned long, state)
  14409. __field(unsigned long, dirtied_when)
  14410. - __dynamic_array(char, cgroup,
  14411. - __trace_wb_cgroup_size(inode_to_wb(inode)))
  14412. + __field(unsigned int, cgroup_ino)
  14413. ),
  14414. TP_fast_assign(
  14415. @@ -619,16 +588,16 @@
  14416. __entry->ino = inode->i_ino;
  14417. __entry->state = inode->i_state;
  14418. __entry->dirtied_when = inode->dirtied_when;
  14419. - __trace_wb_assign_cgroup(__get_str(cgroup), inode_to_wb(inode));
  14420. + __entry->cgroup_ino = __trace_wb_assign_cgroup(inode_to_wb(inode));
  14421. ),
  14422. - TP_printk("bdi %s: ino=%lu state=%s dirtied_when=%lu age=%lu cgroup=%s",
  14423. + TP_printk("bdi %s: ino=%lu state=%s dirtied_when=%lu age=%lu cgroup_ino=%u",
  14424. __entry->name,
  14425. __entry->ino,
  14426. show_inode_state(__entry->state),
  14427. __entry->dirtied_when,
  14428. (jiffies - __entry->dirtied_when) / HZ,
  14429. - __get_str(cgroup)
  14430. + __entry->cgroup_ino
  14431. )
  14432. );
  14433. @@ -684,7 +653,7 @@
  14434. __field(unsigned long, writeback_index)
  14435. __field(long, nr_to_write)
  14436. __field(unsigned long, wrote)
  14437. - __dynamic_array(char, cgroup, __trace_wbc_cgroup_size(wbc))
  14438. + __field(unsigned int, cgroup_ino)
  14439. ),
  14440. TP_fast_assign(
  14441. @@ -696,11 +665,11 @@
  14442. __entry->writeback_index = inode->i_mapping->writeback_index;
  14443. __entry->nr_to_write = nr_to_write;
  14444. __entry->wrote = nr_to_write - wbc->nr_to_write;
  14445. - __trace_wbc_assign_cgroup(__get_str(cgroup), wbc);
  14446. + __entry->cgroup_ino = __trace_wbc_assign_cgroup(wbc);
  14447. ),
  14448. TP_printk("bdi %s: ino=%lu state=%s dirtied_when=%lu age=%lu "
  14449. - "index=%lu to_write=%ld wrote=%lu cgroup=%s",
  14450. + "index=%lu to_write=%ld wrote=%lu cgroup_ino=%u",
  14451. __entry->name,
  14452. __entry->ino,
  14453. show_inode_state(__entry->state),
  14454. @@ -709,7 +678,7 @@
  14455. __entry->writeback_index,
  14456. __entry->nr_to_write,
  14457. __entry->wrote,
  14458. - __get_str(cgroup)
  14459. + __entry->cgroup_ino
  14460. )
  14461. );
  14462. diff -Nur linux-4.4.13.orig/init/Kconfig linux-4.4.13/init/Kconfig
  14463. --- linux-4.4.13.orig/init/Kconfig 2016-06-08 03:14:51.000000000 +0200
  14464. +++ linux-4.4.13/init/Kconfig 2016-06-22 21:55:08.042523867 +0200
  14465. @@ -498,7 +498,7 @@
  14466. config RCU_EXPERT
  14467. bool "Make expert-level adjustments to RCU configuration"
  14468. - default n
  14469. + default y if PREEMPT_RT_FULL
  14470. help
  14471. This option needs to be enabled if you wish to make
  14472. expert-level adjustments to RCU configuration. By default,
  14473. @@ -614,7 +614,7 @@
  14474. config RCU_FAST_NO_HZ
  14475. bool "Accelerate last non-dyntick-idle CPU's grace periods"
  14476. - depends on NO_HZ_COMMON && SMP && RCU_EXPERT
  14477. + depends on NO_HZ_COMMON && SMP && RCU_EXPERT && !PREEMPT_RT_FULL
  14478. default n
  14479. help
  14480. This option permits CPUs to enter dynticks-idle state even if
  14481. @@ -641,7 +641,7 @@
  14482. config RCU_BOOST
  14483. bool "Enable RCU priority boosting"
  14484. depends on RT_MUTEXES && PREEMPT_RCU && RCU_EXPERT
  14485. - default n
  14486. + default y if PREEMPT_RT_FULL
  14487. help
  14488. This option boosts the priority of preempted RCU readers that
  14489. block the current preemptible RCU grace period for too long.
  14490. @@ -1106,6 +1106,7 @@
  14491. config RT_GROUP_SCHED
  14492. bool "Group scheduling for SCHED_RR/FIFO"
  14493. depends on CGROUP_SCHED
  14494. + depends on !PREEMPT_RT_FULL
  14495. default n
  14496. help
  14497. This feature lets you explicitly allocate real CPU bandwidth
  14498. @@ -1719,6 +1720,7 @@
  14499. config SLAB
  14500. bool "SLAB"
  14501. + depends on !PREEMPT_RT_FULL
  14502. help
  14503. The regular slab allocator that is established and known to work
  14504. well in all environments. It organizes cache hot objects in
  14505. @@ -1737,6 +1739,7 @@
  14506. config SLOB
  14507. depends on EXPERT
  14508. bool "SLOB (Simple Allocator)"
  14509. + depends on !PREEMPT_RT_FULL
  14510. help
  14511. SLOB replaces the stock allocator with a drastically simpler
  14512. allocator. SLOB is generally more space efficient but
  14513. @@ -1746,7 +1749,7 @@
  14514. config SLUB_CPU_PARTIAL
  14515. default y
  14516. - depends on SLUB && SMP
  14517. + depends on SLUB && SMP && !PREEMPT_RT_FULL
  14518. bool "SLUB per cpu partial cache"
  14519. help
  14520. Per cpu partial caches accellerate objects allocation and freeing
  14521. diff -Nur linux-4.4.13.orig/init/main.c linux-4.4.13/init/main.c
  14522. --- linux-4.4.13.orig/init/main.c 2016-06-08 03:14:51.000000000 +0200
  14523. +++ linux-4.4.13/init/main.c 2016-06-22 21:55:08.042523867 +0200
  14524. @@ -530,6 +530,7 @@
  14525. setup_command_line(command_line);
  14526. setup_nr_cpu_ids();
  14527. setup_per_cpu_areas();
  14528. + softirq_early_init();
  14529. smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
  14530. build_all_zonelists(NULL, NULL);
  14531. diff -Nur linux-4.4.13.orig/init/Makefile linux-4.4.13/init/Makefile
  14532. --- linux-4.4.13.orig/init/Makefile 2016-06-08 03:14:51.000000000 +0200
  14533. +++ linux-4.4.13/init/Makefile 2016-06-22 21:55:08.042523867 +0200
  14534. @@ -33,4 +33,4 @@
  14535. include/generated/compile.h: FORCE
  14536. @$($(quiet)chk_compile.h)
  14537. $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \
  14538. - "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" "$(CC) $(KBUILD_CFLAGS)"
  14539. + "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" "$(CONFIG_PREEMPT_RT_FULL)" "$(CC) $(KBUILD_CFLAGS)"
  14540. diff -Nur linux-4.4.13.orig/ipc/msg.c linux-4.4.13/ipc/msg.c
  14541. --- linux-4.4.13.orig/ipc/msg.c 2016-06-08 03:14:51.000000000 +0200
  14542. +++ linux-4.4.13/ipc/msg.c 2016-06-22 21:55:08.042523867 +0200
  14543. @@ -183,20 +183,14 @@
  14544. }
  14545. }
  14546. -static void expunge_all(struct msg_queue *msq, int res)
  14547. +static void expunge_all(struct msg_queue *msq, int res,
  14548. + struct wake_q_head *wake_q)
  14549. {
  14550. struct msg_receiver *msr, *t;
  14551. list_for_each_entry_safe(msr, t, &msq->q_receivers, r_list) {
  14552. - msr->r_msg = NULL; /* initialize expunge ordering */
  14553. - wake_up_process(msr->r_tsk);
  14554. - /*
  14555. - * Ensure that the wakeup is visible before setting r_msg as
  14556. - * the receiving end depends on it: either spinning on a nil,
  14557. - * or dealing with -EAGAIN cases. See lockless receive part 1
  14558. - * and 2 in do_msgrcv().
  14559. - */
  14560. - smp_wmb(); /* barrier (B) */
  14561. +
  14562. + wake_q_add(wake_q, msr->r_tsk);
  14563. msr->r_msg = ERR_PTR(res);
  14564. }
  14565. }
  14566. @@ -213,11 +207,13 @@
  14567. {
  14568. struct msg_msg *msg, *t;
  14569. struct msg_queue *msq = container_of(ipcp, struct msg_queue, q_perm);
  14570. + WAKE_Q(wake_q);
  14571. - expunge_all(msq, -EIDRM);
  14572. + expunge_all(msq, -EIDRM, &wake_q);
  14573. ss_wakeup(&msq->q_senders, 1);
  14574. msg_rmid(ns, msq);
  14575. ipc_unlock_object(&msq->q_perm);
  14576. + wake_up_q(&wake_q);
  14577. rcu_read_unlock();
  14578. list_for_each_entry_safe(msg, t, &msq->q_messages, m_list) {
  14579. @@ -342,6 +338,7 @@
  14580. struct kern_ipc_perm *ipcp;
  14581. struct msqid64_ds uninitialized_var(msqid64);
  14582. struct msg_queue *msq;
  14583. + WAKE_Q(wake_q);
  14584. int err;
  14585. if (cmd == IPC_SET) {
  14586. @@ -389,7 +386,7 @@
  14587. /* sleeping receivers might be excluded by
  14588. * stricter permissions.
  14589. */
  14590. - expunge_all(msq, -EAGAIN);
  14591. + expunge_all(msq, -EAGAIN, &wake_q);
  14592. /* sleeping senders might be able to send
  14593. * due to a larger queue size.
  14594. */
  14595. @@ -402,6 +399,7 @@
  14596. out_unlock0:
  14597. ipc_unlock_object(&msq->q_perm);
  14598. + wake_up_q(&wake_q);
  14599. out_unlock1:
  14600. rcu_read_unlock();
  14601. out_up:
  14602. @@ -566,7 +564,8 @@
  14603. return 0;
  14604. }
  14605. -static inline int pipelined_send(struct msg_queue *msq, struct msg_msg *msg)
  14606. +static inline int pipelined_send(struct msg_queue *msq, struct msg_msg *msg,
  14607. + struct wake_q_head *wake_q)
  14608. {
  14609. struct msg_receiver *msr, *t;
  14610. @@ -577,27 +576,13 @@
  14611. list_del(&msr->r_list);
  14612. if (msr->r_maxsize < msg->m_ts) {
  14613. - /* initialize pipelined send ordering */
  14614. - msr->r_msg = NULL;
  14615. - wake_up_process(msr->r_tsk);
  14616. - /* barrier (B) see barrier comment below */
  14617. - smp_wmb();
  14618. + wake_q_add(wake_q, msr->r_tsk);
  14619. msr->r_msg = ERR_PTR(-E2BIG);
  14620. } else {
  14621. - msr->r_msg = NULL;
  14622. msq->q_lrpid = task_pid_vnr(msr->r_tsk);
  14623. msq->q_rtime = get_seconds();
  14624. - wake_up_process(msr->r_tsk);
  14625. - /*
  14626. - * Ensure that the wakeup is visible before
  14627. - * setting r_msg, as the receiving can otherwise
  14628. - * exit - once r_msg is set, the receiver can
  14629. - * continue. See lockless receive part 1 and 2
  14630. - * in do_msgrcv(). Barrier (B).
  14631. - */
  14632. - smp_wmb();
  14633. + wake_q_add(wake_q, msr->r_tsk);
  14634. msr->r_msg = msg;
  14635. -
  14636. return 1;
  14637. }
  14638. }
  14639. @@ -613,6 +598,7 @@
  14640. struct msg_msg *msg;
  14641. int err;
  14642. struct ipc_namespace *ns;
  14643. + WAKE_Q(wake_q);
  14644. ns = current->nsproxy->ipc_ns;
  14645. @@ -698,7 +684,7 @@
  14646. msq->q_lspid = task_tgid_vnr(current);
  14647. msq->q_stime = get_seconds();
  14648. - if (!pipelined_send(msq, msg)) {
  14649. + if (!pipelined_send(msq, msg, &wake_q)) {
  14650. /* no one is waiting for this message, enqueue it */
  14651. list_add_tail(&msg->m_list, &msq->q_messages);
  14652. msq->q_cbytes += msgsz;
  14653. @@ -712,6 +698,7 @@
  14654. out_unlock0:
  14655. ipc_unlock_object(&msq->q_perm);
  14656. + wake_up_q(&wake_q);
  14657. out_unlock1:
  14658. rcu_read_unlock();
  14659. if (msg != NULL)
  14660. @@ -932,57 +919,25 @@
  14661. rcu_read_lock();
  14662. /* Lockless receive, part 2:
  14663. - * Wait until pipelined_send or expunge_all are outside of
  14664. - * wake_up_process(). There is a race with exit(), see
  14665. - * ipc/mqueue.c for the details. The correct serialization
  14666. - * ensures that a receiver cannot continue without the wakeup
  14667. - * being visibible _before_ setting r_msg:
  14668. + * The work in pipelined_send() and expunge_all():
  14669. + * - Set pointer to message
  14670. + * - Queue the receiver task for later wakeup
  14671. + * - Wake up the process after the lock is dropped.
  14672. *
  14673. - * CPU 0 CPU 1
  14674. - * <loop receiver>
  14675. - * smp_rmb(); (A) <-- pair -. <waker thread>
  14676. - * <load ->r_msg> | msr->r_msg = NULL;
  14677. - * | wake_up_process();
  14678. - * <continue> `------> smp_wmb(); (B)
  14679. - * msr->r_msg = msg;
  14680. - *
  14681. - * Where (A) orders the message value read and where (B) orders
  14682. - * the write to the r_msg -- done in both pipelined_send and
  14683. - * expunge_all.
  14684. + * Should the process wake up before this wakeup (due to a
  14685. + * signal) it will either see the message and continue …
  14686. */
  14687. - for (;;) {
  14688. - /*
  14689. - * Pairs with writer barrier in pipelined_send
  14690. - * or expunge_all.
  14691. - */
  14692. - smp_rmb(); /* barrier (A) */
  14693. - msg = (struct msg_msg *)msr_d.r_msg;
  14694. - if (msg)
  14695. - break;
  14696. - /*
  14697. - * The cpu_relax() call is a compiler barrier
  14698. - * which forces everything in this loop to be
  14699. - * re-loaded.
  14700. - */
  14701. - cpu_relax();
  14702. - }
  14703. -
  14704. - /* Lockless receive, part 3:
  14705. - * If there is a message or an error then accept it without
  14706. - * locking.
  14707. - */
  14708. + msg = (struct msg_msg *)msr_d.r_msg;
  14709. if (msg != ERR_PTR(-EAGAIN))
  14710. goto out_unlock1;
  14711. - /* Lockless receive, part 3:
  14712. - * Acquire the queue spinlock.
  14713. - */
  14714. + /*
  14715. + * … or see -EAGAIN, acquire the lock to check the message
  14716. + * again.
  14717. + */
  14718. ipc_lock_object(&msq->q_perm);
  14719. - /* Lockless receive, part 4:
  14720. - * Repeat test after acquiring the spinlock.
  14721. - */
  14722. msg = (struct msg_msg *)msr_d.r_msg;
  14723. if (msg != ERR_PTR(-EAGAIN))
  14724. goto out_unlock0;
  14725. diff -Nur linux-4.4.13.orig/ipc/sem.c linux-4.4.13/ipc/sem.c
  14726. --- linux-4.4.13.orig/ipc/sem.c 2016-06-08 03:14:51.000000000 +0200
  14727. +++ linux-4.4.13/ipc/sem.c 2016-06-22 21:55:08.042523867 +0200
  14728. @@ -690,6 +690,13 @@
  14729. static void wake_up_sem_queue_prepare(struct list_head *pt,
  14730. struct sem_queue *q, int error)
  14731. {
  14732. +#ifdef CONFIG_PREEMPT_RT_BASE
  14733. + struct task_struct *p = q->sleeper;
  14734. + get_task_struct(p);
  14735. + q->status = error;
  14736. + wake_up_process(p);
  14737. + put_task_struct(p);
  14738. +#else
  14739. if (list_empty(pt)) {
  14740. /*
  14741. * Hold preempt off so that we don't get preempted and have the
  14742. @@ -701,6 +708,7 @@
  14743. q->pid = error;
  14744. list_add_tail(&q->list, pt);
  14745. +#endif
  14746. }
  14747. /**
  14748. @@ -714,6 +722,7 @@
  14749. */
  14750. static void wake_up_sem_queue_do(struct list_head *pt)
  14751. {
  14752. +#ifndef CONFIG_PREEMPT_RT_BASE
  14753. struct sem_queue *q, *t;
  14754. int did_something;
  14755. @@ -726,6 +735,7 @@
  14756. }
  14757. if (did_something)
  14758. preempt_enable();
  14759. +#endif
  14760. }
  14761. static void unlink_queue(struct sem_array *sma, struct sem_queue *q)
  14762. diff -Nur linux-4.4.13.orig/kernel/cgroup.c linux-4.4.13/kernel/cgroup.c
  14763. --- linux-4.4.13.orig/kernel/cgroup.c 2016-06-08 03:14:51.000000000 +0200
  14764. +++ linux-4.4.13/kernel/cgroup.c 2016-06-22 21:55:08.042523867 +0200
  14765. @@ -4737,10 +4737,10 @@
  14766. queue_work(cgroup_destroy_wq, &css->destroy_work);
  14767. }
  14768. -static void css_release_work_fn(struct work_struct *work)
  14769. +static void css_release_work_fn(struct swork_event *sev)
  14770. {
  14771. struct cgroup_subsys_state *css =
  14772. - container_of(work, struct cgroup_subsys_state, destroy_work);
  14773. + container_of(sev, struct cgroup_subsys_state, destroy_swork);
  14774. struct cgroup_subsys *ss = css->ss;
  14775. struct cgroup *cgrp = css->cgroup;
  14776. @@ -4779,8 +4779,8 @@
  14777. struct cgroup_subsys_state *css =
  14778. container_of(ref, struct cgroup_subsys_state, refcnt);
  14779. - INIT_WORK(&css->destroy_work, css_release_work_fn);
  14780. - queue_work(cgroup_destroy_wq, &css->destroy_work);
  14781. + INIT_SWORK(&css->destroy_swork, css_release_work_fn);
  14782. + swork_queue(&css->destroy_swork);
  14783. }
  14784. static void init_and_link_css(struct cgroup_subsys_state *css,
  14785. @@ -5396,6 +5396,7 @@
  14786. */
  14787. cgroup_destroy_wq = alloc_workqueue("cgroup_destroy", 0, 1);
  14788. BUG_ON(!cgroup_destroy_wq);
  14789. + BUG_ON(swork_get());
  14790. /*
  14791. * Used to destroy pidlists and separate to serve as flush domain.
  14792. diff -Nur linux-4.4.13.orig/kernel/cpu.c linux-4.4.13/kernel/cpu.c
  14793. --- linux-4.4.13.orig/kernel/cpu.c 2016-06-08 03:14:51.000000000 +0200
  14794. +++ linux-4.4.13/kernel/cpu.c 2016-06-22 21:55:08.046523867 +0200
  14795. @@ -75,8 +75,8 @@
  14796. #endif
  14797. } cpu_hotplug = {
  14798. .active_writer = NULL,
  14799. - .wq = __WAIT_QUEUE_HEAD_INITIALIZER(cpu_hotplug.wq),
  14800. .lock = __MUTEX_INITIALIZER(cpu_hotplug.lock),
  14801. + .wq = __WAIT_QUEUE_HEAD_INITIALIZER(cpu_hotplug.wq),
  14802. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  14803. .dep_map = {.name = "cpu_hotplug.lock" },
  14804. #endif
  14805. @@ -89,6 +89,289 @@
  14806. #define cpuhp_lock_acquire() lock_map_acquire(&cpu_hotplug.dep_map)
  14807. #define cpuhp_lock_release() lock_map_release(&cpu_hotplug.dep_map)
  14808. +/**
  14809. + * hotplug_pcp - per cpu hotplug descriptor
  14810. + * @unplug: set when pin_current_cpu() needs to sync tasks
  14811. + * @sync_tsk: the task that waits for tasks to finish pinned sections
  14812. + * @refcount: counter of tasks in pinned sections
  14813. + * @grab_lock: set when the tasks entering pinned sections should wait
  14814. + * @synced: notifier for @sync_tsk to tell cpu_down it's finished
  14815. + * @mutex: the mutex to make tasks wait (used when @grab_lock is true)
  14816. + * @mutex_init: zero if the mutex hasn't been initialized yet.
  14817. + *
  14818. + * Although @unplug and @sync_tsk may point to the same task, the @unplug
  14819. + * is used as a flag and still exists after @sync_tsk has exited and
  14820. + * @sync_tsk set to NULL.
  14821. + */
  14822. +struct hotplug_pcp {
  14823. + struct task_struct *unplug;
  14824. + struct task_struct *sync_tsk;
  14825. + int refcount;
  14826. + int grab_lock;
  14827. + struct completion synced;
  14828. + struct completion unplug_wait;
  14829. +#ifdef CONFIG_PREEMPT_RT_FULL
  14830. + /*
  14831. + * Note, on PREEMPT_RT, the hotplug lock must save the state of
  14832. + * the task, otherwise the mutex will cause the task to fail
  14833. + * to sleep when required. (Because it's called from migrate_disable())
  14834. + *
  14835. + * The spinlock_t on PREEMPT_RT is a mutex that saves the task's
  14836. + * state.
  14837. + */
  14838. + spinlock_t lock;
  14839. +#else
  14840. + struct mutex mutex;
  14841. +#endif
  14842. + int mutex_init;
  14843. +};
  14844. +
  14845. +#ifdef CONFIG_PREEMPT_RT_FULL
  14846. +# define hotplug_lock(hp) rt_spin_lock__no_mg(&(hp)->lock)
  14847. +# define hotplug_unlock(hp) rt_spin_unlock__no_mg(&(hp)->lock)
  14848. +#else
  14849. +# define hotplug_lock(hp) mutex_lock(&(hp)->mutex)
  14850. +# define hotplug_unlock(hp) mutex_unlock(&(hp)->mutex)
  14851. +#endif
  14852. +
  14853. +static DEFINE_PER_CPU(struct hotplug_pcp, hotplug_pcp);
  14854. +
  14855. +/**
  14856. + * pin_current_cpu - Prevent the current cpu from being unplugged
  14857. + *
  14858. + * Lightweight version of get_online_cpus() to prevent cpu from being
  14859. + * unplugged when code runs in a migration disabled region.
  14860. + *
  14861. + * Must be called with preemption disabled (preempt_count = 1)!
  14862. + */
  14863. +void pin_current_cpu(void)
  14864. +{
  14865. + struct hotplug_pcp *hp;
  14866. + int force = 0;
  14867. +
  14868. +retry:
  14869. + hp = this_cpu_ptr(&hotplug_pcp);
  14870. +
  14871. + if (!hp->unplug || hp->refcount || force || preempt_count() > 1 ||
  14872. + hp->unplug == current) {
  14873. + hp->refcount++;
  14874. + return;
  14875. + }
  14876. + if (hp->grab_lock) {
  14877. + preempt_enable();
  14878. + hotplug_lock(hp);
  14879. + hotplug_unlock(hp);
  14880. + } else {
  14881. + preempt_enable();
  14882. + /*
  14883. + * Try to push this task off of this CPU.
  14884. + */
  14885. + if (!migrate_me()) {
  14886. + preempt_disable();
  14887. + hp = this_cpu_ptr(&hotplug_pcp);
  14888. + if (!hp->grab_lock) {
  14889. + /*
  14890. + * Just let it continue it's already pinned
  14891. + * or about to sleep.
  14892. + */
  14893. + force = 1;
  14894. + goto retry;
  14895. + }
  14896. + preempt_enable();
  14897. + }
  14898. + }
  14899. + preempt_disable();
  14900. + goto retry;
  14901. +}
  14902. +
  14903. +/**
  14904. + * unpin_current_cpu - Allow unplug of current cpu
  14905. + *
  14906. + * Must be called with preemption or interrupts disabled!
  14907. + */
  14908. +void unpin_current_cpu(void)
  14909. +{
  14910. + struct hotplug_pcp *hp = this_cpu_ptr(&hotplug_pcp);
  14911. +
  14912. + WARN_ON(hp->refcount <= 0);
  14913. +
  14914. + /* This is safe. sync_unplug_thread is pinned to this cpu */
  14915. + if (!--hp->refcount && hp->unplug && hp->unplug != current)
  14916. + wake_up_process(hp->unplug);
  14917. +}
  14918. +
  14919. +static void wait_for_pinned_cpus(struct hotplug_pcp *hp)
  14920. +{
  14921. + set_current_state(TASK_UNINTERRUPTIBLE);
  14922. + while (hp->refcount) {
  14923. + schedule_preempt_disabled();
  14924. + set_current_state(TASK_UNINTERRUPTIBLE);
  14925. + }
  14926. +}
  14927. +
  14928. +static int sync_unplug_thread(void *data)
  14929. +{
  14930. + struct hotplug_pcp *hp = data;
  14931. +
  14932. + wait_for_completion(&hp->unplug_wait);
  14933. + preempt_disable();
  14934. + hp->unplug = current;
  14935. + wait_for_pinned_cpus(hp);
  14936. +
  14937. + /*
  14938. + * This thread will synchronize the cpu_down() with threads
  14939. + * that have pinned the CPU. When the pinned CPU count reaches
  14940. + * zero, we inform the cpu_down code to continue to the next step.
  14941. + */
  14942. + set_current_state(TASK_UNINTERRUPTIBLE);
  14943. + preempt_enable();
  14944. + complete(&hp->synced);
  14945. +
  14946. + /*
  14947. + * If all succeeds, the next step will need tasks to wait till
  14948. + * the CPU is offline before continuing. To do this, the grab_lock
  14949. + * is set and tasks going into pin_current_cpu() will block on the
  14950. + * mutex. But we still need to wait for those that are already in
  14951. + * pinned CPU sections. If the cpu_down() failed, the kthread_should_stop()
  14952. + * will kick this thread out.
  14953. + */
  14954. + while (!hp->grab_lock && !kthread_should_stop()) {
  14955. + schedule();
  14956. + set_current_state(TASK_UNINTERRUPTIBLE);
  14957. + }
  14958. +
  14959. + /* Make sure grab_lock is seen before we see a stale completion */
  14960. + smp_mb();
  14961. +
  14962. + /*
  14963. + * Now just before cpu_down() enters stop machine, we need to make
  14964. + * sure all tasks that are in pinned CPU sections are out, and new
  14965. + * tasks will now grab the lock, keeping them from entering pinned
  14966. + * CPU sections.
  14967. + */
  14968. + if (!kthread_should_stop()) {
  14969. + preempt_disable();
  14970. + wait_for_pinned_cpus(hp);
  14971. + preempt_enable();
  14972. + complete(&hp->synced);
  14973. + }
  14974. +
  14975. + set_current_state(TASK_UNINTERRUPTIBLE);
  14976. + while (!kthread_should_stop()) {
  14977. + schedule();
  14978. + set_current_state(TASK_UNINTERRUPTIBLE);
  14979. + }
  14980. + set_current_state(TASK_RUNNING);
  14981. +
  14982. + /*
  14983. + * Force this thread off this CPU as it's going down and
  14984. + * we don't want any more work on this CPU.
  14985. + */
  14986. + current->flags &= ~PF_NO_SETAFFINITY;
  14987. + set_cpus_allowed_ptr(current, cpu_present_mask);
  14988. + migrate_me();
  14989. + return 0;
  14990. +}
  14991. +
  14992. +static void __cpu_unplug_sync(struct hotplug_pcp *hp)
  14993. +{
  14994. + wake_up_process(hp->sync_tsk);
  14995. + wait_for_completion(&hp->synced);
  14996. +}
  14997. +
  14998. +static void __cpu_unplug_wait(unsigned int cpu)
  14999. +{
  15000. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  15001. +
  15002. + complete(&hp->unplug_wait);
  15003. + wait_for_completion(&hp->synced);
  15004. +}
  15005. +
  15006. +/*
  15007. + * Start the sync_unplug_thread on the target cpu and wait for it to
  15008. + * complete.
  15009. + */
  15010. +static int cpu_unplug_begin(unsigned int cpu)
  15011. +{
  15012. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  15013. + int err;
  15014. +
  15015. + /* Protected by cpu_hotplug.lock */
  15016. + if (!hp->mutex_init) {
  15017. +#ifdef CONFIG_PREEMPT_RT_FULL
  15018. + spin_lock_init(&hp->lock);
  15019. +#else
  15020. + mutex_init(&hp->mutex);
  15021. +#endif
  15022. + hp->mutex_init = 1;
  15023. + }
  15024. +
  15025. + /* Inform the scheduler to migrate tasks off this CPU */
  15026. + tell_sched_cpu_down_begin(cpu);
  15027. +
  15028. + init_completion(&hp->synced);
  15029. + init_completion(&hp->unplug_wait);
  15030. +
  15031. + hp->sync_tsk = kthread_create(sync_unplug_thread, hp, "sync_unplug/%d", cpu);
  15032. + if (IS_ERR(hp->sync_tsk)) {
  15033. + err = PTR_ERR(hp->sync_tsk);
  15034. + hp->sync_tsk = NULL;
  15035. + return err;
  15036. + }
  15037. + kthread_bind(hp->sync_tsk, cpu);
  15038. +
  15039. + /*
  15040. + * Wait for tasks to get out of the pinned sections,
  15041. + * it's still OK if new tasks enter. Some CPU notifiers will
  15042. + * wait for tasks that are going to enter these sections and
  15043. + * we must not have them block.
  15044. + */
  15045. + wake_up_process(hp->sync_tsk);
  15046. + return 0;
  15047. +}
  15048. +
  15049. +static void cpu_unplug_sync(unsigned int cpu)
  15050. +{
  15051. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  15052. +
  15053. + init_completion(&hp->synced);
  15054. + /* The completion needs to be initialzied before setting grab_lock */
  15055. + smp_wmb();
  15056. +
  15057. + /* Grab the mutex before setting grab_lock */
  15058. + hotplug_lock(hp);
  15059. + hp->grab_lock = 1;
  15060. +
  15061. + /*
  15062. + * The CPU notifiers have been completed.
  15063. + * Wait for tasks to get out of pinned CPU sections and have new
  15064. + * tasks block until the CPU is completely down.
  15065. + */
  15066. + __cpu_unplug_sync(hp);
  15067. +
  15068. + /* All done with the sync thread */
  15069. + kthread_stop(hp->sync_tsk);
  15070. + hp->sync_tsk = NULL;
  15071. +}
  15072. +
  15073. +static void cpu_unplug_done(unsigned int cpu)
  15074. +{
  15075. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  15076. +
  15077. + hp->unplug = NULL;
  15078. + /* Let all tasks know cpu unplug is finished before cleaning up */
  15079. + smp_wmb();
  15080. +
  15081. + if (hp->sync_tsk)
  15082. + kthread_stop(hp->sync_tsk);
  15083. +
  15084. + if (hp->grab_lock) {
  15085. + hotplug_unlock(hp);
  15086. + /* protected by cpu_hotplug.lock */
  15087. + hp->grab_lock = 0;
  15088. + }
  15089. + tell_sched_cpu_down_done(cpu);
  15090. +}
  15091. void get_online_cpus(void)
  15092. {
  15093. @@ -338,13 +621,15 @@
  15094. /* Requires cpu_add_remove_lock to be held */
  15095. static int _cpu_down(unsigned int cpu, int tasks_frozen)
  15096. {
  15097. - int err, nr_calls = 0;
  15098. + int mycpu, err, nr_calls = 0;
  15099. void *hcpu = (void *)(long)cpu;
  15100. unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
  15101. struct take_cpu_down_param tcd_param = {
  15102. .mod = mod,
  15103. .hcpu = hcpu,
  15104. };
  15105. + cpumask_var_t cpumask;
  15106. + cpumask_var_t cpumask_org;
  15107. if (num_online_cpus() == 1)
  15108. return -EBUSY;
  15109. @@ -352,7 +637,34 @@
  15110. if (!cpu_online(cpu))
  15111. return -EINVAL;
  15112. + /* Move the downtaker off the unplug cpu */
  15113. + if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
  15114. + return -ENOMEM;
  15115. + if (!alloc_cpumask_var(&cpumask_org, GFP_KERNEL)) {
  15116. + free_cpumask_var(cpumask);
  15117. + return -ENOMEM;
  15118. + }
  15119. +
  15120. + cpumask_copy(cpumask_org, tsk_cpus_allowed(current));
  15121. + cpumask_andnot(cpumask, cpu_online_mask, cpumask_of(cpu));
  15122. + set_cpus_allowed_ptr(current, cpumask);
  15123. + free_cpumask_var(cpumask);
  15124. + migrate_disable();
  15125. + mycpu = smp_processor_id();
  15126. + if (mycpu == cpu) {
  15127. + printk(KERN_ERR "Yuck! Still on unplug CPU\n!");
  15128. + migrate_enable();
  15129. + err = -EBUSY;
  15130. + goto restore_cpus;
  15131. + }
  15132. + migrate_enable();
  15133. +
  15134. cpu_hotplug_begin();
  15135. + err = cpu_unplug_begin(cpu);
  15136. + if (err) {
  15137. + printk("cpu_unplug_begin(%d) failed\n", cpu);
  15138. + goto out_cancel;
  15139. + }
  15140. err = __cpu_notify(CPU_DOWN_PREPARE | mod, hcpu, -1, &nr_calls);
  15141. if (err) {
  15142. @@ -378,8 +690,12 @@
  15143. else
  15144. synchronize_rcu();
  15145. + __cpu_unplug_wait(cpu);
  15146. smpboot_park_threads(cpu);
  15147. + /* Notifiers are done. Don't let any more tasks pin this CPU. */
  15148. + cpu_unplug_sync(cpu);
  15149. +
  15150. /*
  15151. * Prevent irq alloc/free while the dying cpu reorganizes the
  15152. * interrupt affinities.
  15153. @@ -424,9 +740,14 @@
  15154. check_for_tasks(cpu);
  15155. out_release:
  15156. + cpu_unplug_done(cpu);
  15157. +out_cancel:
  15158. cpu_hotplug_done();
  15159. if (!err)
  15160. cpu_notify_nofail(CPU_POST_DEAD | mod, hcpu);
  15161. +restore_cpus:
  15162. + set_cpus_allowed_ptr(current, cpumask_org);
  15163. + free_cpumask_var(cpumask_org);
  15164. return err;
  15165. }
  15166. diff -Nur linux-4.4.13.orig/kernel/debug/kdb/kdb_io.c linux-4.4.13/kernel/debug/kdb/kdb_io.c
  15167. --- linux-4.4.13.orig/kernel/debug/kdb/kdb_io.c 2016-06-08 03:14:51.000000000 +0200
  15168. +++ linux-4.4.13/kernel/debug/kdb/kdb_io.c 2016-06-22 21:55:08.046523867 +0200
  15169. @@ -554,7 +554,6 @@
  15170. int linecount;
  15171. int colcount;
  15172. int logging, saved_loglevel = 0;
  15173. - int saved_trap_printk;
  15174. int got_printf_lock = 0;
  15175. int retlen = 0;
  15176. int fnd, len;
  15177. @@ -565,8 +564,6 @@
  15178. unsigned long uninitialized_var(flags);
  15179. preempt_disable();
  15180. - saved_trap_printk = kdb_trap_printk;
  15181. - kdb_trap_printk = 0;
  15182. /* Serialize kdb_printf if multiple cpus try to write at once.
  15183. * But if any cpu goes recursive in kdb, just print the output,
  15184. @@ -855,7 +852,6 @@
  15185. } else {
  15186. __release(kdb_printf_lock);
  15187. }
  15188. - kdb_trap_printk = saved_trap_printk;
  15189. preempt_enable();
  15190. return retlen;
  15191. }
  15192. @@ -865,9 +861,11 @@
  15193. va_list ap;
  15194. int r;
  15195. + kdb_trap_printk++;
  15196. va_start(ap, fmt);
  15197. r = vkdb_printf(KDB_MSGSRC_INTERNAL, fmt, ap);
  15198. va_end(ap);
  15199. + kdb_trap_printk--;
  15200. return r;
  15201. }
  15202. diff -Nur linux-4.4.13.orig/kernel/events/core.c linux-4.4.13/kernel/events/core.c
  15203. --- linux-4.4.13.orig/kernel/events/core.c 2016-06-08 03:14:51.000000000 +0200
  15204. +++ linux-4.4.13/kernel/events/core.c 2016-06-22 21:55:08.046523867 +0200
  15205. @@ -802,6 +802,7 @@
  15206. raw_spin_lock_init(&cpuctx->hrtimer_lock);
  15207. hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED);
  15208. timer->function = perf_mux_hrtimer_handler;
  15209. + timer->irqsafe = 1;
  15210. }
  15211. static int perf_mux_hrtimer_restart(struct perf_cpu_context *cpuctx)
  15212. @@ -7219,6 +7220,7 @@
  15213. hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  15214. hwc->hrtimer.function = perf_swevent_hrtimer;
  15215. + hwc->hrtimer.irqsafe = 1;
  15216. /*
  15217. * Since hrtimers have a fixed rate, we can do a static freq->period
  15218. diff -Nur linux-4.4.13.orig/kernel/exit.c linux-4.4.13/kernel/exit.c
  15219. --- linux-4.4.13.orig/kernel/exit.c 2016-06-08 03:14:51.000000000 +0200
  15220. +++ linux-4.4.13/kernel/exit.c 2016-06-22 21:55:08.046523867 +0200
  15221. @@ -144,7 +144,7 @@
  15222. * Do this under ->siglock, we can race with another thread
  15223. * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
  15224. */
  15225. - flush_sigqueue(&tsk->pending);
  15226. + flush_task_sigqueue(tsk);
  15227. tsk->sighand = NULL;
  15228. spin_unlock(&sighand->siglock);
  15229. diff -Nur linux-4.4.13.orig/kernel/fork.c linux-4.4.13/kernel/fork.c
  15230. --- linux-4.4.13.orig/kernel/fork.c 2016-06-08 03:14:51.000000000 +0200
  15231. +++ linux-4.4.13/kernel/fork.c 2016-06-22 21:55:08.046523867 +0200
  15232. @@ -108,7 +108,7 @@
  15233. DEFINE_PER_CPU(unsigned long, process_counts) = 0;
  15234. -__cacheline_aligned DEFINE_RWLOCK(tasklist_lock); /* outer */
  15235. +DEFINE_RWLOCK(tasklist_lock); /* outer */
  15236. #ifdef CONFIG_PROVE_RCU
  15237. int lockdep_tasklist_lock_is_held(void)
  15238. @@ -244,7 +244,9 @@
  15239. if (atomic_dec_and_test(&sig->sigcnt))
  15240. free_signal_struct(sig);
  15241. }
  15242. -
  15243. +#ifdef CONFIG_PREEMPT_RT_BASE
  15244. +static
  15245. +#endif
  15246. void __put_task_struct(struct task_struct *tsk)
  15247. {
  15248. WARN_ON(!tsk->exit_state);
  15249. @@ -261,7 +263,18 @@
  15250. if (!profile_handoff_task(tsk))
  15251. free_task(tsk);
  15252. }
  15253. +#ifndef CONFIG_PREEMPT_RT_BASE
  15254. EXPORT_SYMBOL_GPL(__put_task_struct);
  15255. +#else
  15256. +void __put_task_struct_cb(struct rcu_head *rhp)
  15257. +{
  15258. + struct task_struct *tsk = container_of(rhp, struct task_struct, put_rcu);
  15259. +
  15260. + __put_task_struct(tsk);
  15261. +
  15262. +}
  15263. +EXPORT_SYMBOL_GPL(__put_task_struct_cb);
  15264. +#endif
  15265. void __init __weak arch_task_cache_init(void) { }
  15266. @@ -689,6 +702,19 @@
  15267. }
  15268. EXPORT_SYMBOL_GPL(__mmdrop);
  15269. +#ifdef CONFIG_PREEMPT_RT_BASE
  15270. +/*
  15271. + * RCU callback for delayed mm drop. Not strictly rcu, but we don't
  15272. + * want another facility to make this work.
  15273. + */
  15274. +void __mmdrop_delayed(struct rcu_head *rhp)
  15275. +{
  15276. + struct mm_struct *mm = container_of(rhp, struct mm_struct, delayed_drop);
  15277. +
  15278. + __mmdrop(mm);
  15279. +}
  15280. +#endif
  15281. +
  15282. /*
  15283. * Decrement the use count and release all resources for an mm.
  15284. */
  15285. @@ -1218,6 +1244,9 @@
  15286. */
  15287. static void posix_cpu_timers_init(struct task_struct *tsk)
  15288. {
  15289. +#ifdef CONFIG_PREEMPT_RT_BASE
  15290. + tsk->posix_timer_list = NULL;
  15291. +#endif
  15292. tsk->cputime_expires.prof_exp = 0;
  15293. tsk->cputime_expires.virt_exp = 0;
  15294. tsk->cputime_expires.sched_exp = 0;
  15295. @@ -1343,15 +1372,16 @@
  15296. spin_lock_init(&p->alloc_lock);
  15297. init_sigpending(&p->pending);
  15298. + p->sigqueue_cache = NULL;
  15299. p->utime = p->stime = p->gtime = 0;
  15300. p->utimescaled = p->stimescaled = 0;
  15301. prev_cputime_init(&p->prev_cputime);
  15302. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  15303. - seqlock_init(&p->vtime_seqlock);
  15304. + seqcount_init(&p->vtime_seqcount);
  15305. p->vtime_snap = 0;
  15306. - p->vtime_snap_whence = VTIME_SLEEPING;
  15307. + p->vtime_snap_whence = VTIME_INACTIVE;
  15308. #endif
  15309. #if defined(SPLIT_RSS_COUNTING)
  15310. diff -Nur linux-4.4.13.orig/kernel/futex.c linux-4.4.13/kernel/futex.c
  15311. --- linux-4.4.13.orig/kernel/futex.c 2016-06-08 03:14:51.000000000 +0200
  15312. +++ linux-4.4.13/kernel/futex.c 2016-06-22 21:55:08.046523867 +0200
  15313. @@ -815,7 +815,9 @@
  15314. * task still owns the PI-state:
  15315. */
  15316. if (head->next != next) {
  15317. + raw_spin_unlock_irq(&curr->pi_lock);
  15318. spin_unlock(&hb->lock);
  15319. + raw_spin_lock_irq(&curr->pi_lock);
  15320. continue;
  15321. }
  15322. @@ -1210,6 +1212,7 @@
  15323. struct futex_pi_state *pi_state = this->pi_state;
  15324. u32 uninitialized_var(curval), newval;
  15325. WAKE_Q(wake_q);
  15326. + WAKE_Q(wake_sleeper_q);
  15327. bool deboost;
  15328. int ret = 0;
  15329. @@ -1223,7 +1226,7 @@
  15330. if (pi_state->owner != current)
  15331. return -EINVAL;
  15332. - raw_spin_lock(&pi_state->pi_mutex.wait_lock);
  15333. + raw_spin_lock_irq(&pi_state->pi_mutex.wait_lock);
  15334. new_owner = rt_mutex_next_owner(&pi_state->pi_mutex);
  15335. /*
  15336. @@ -1259,24 +1262,25 @@
  15337. ret = -EINVAL;
  15338. }
  15339. if (ret) {
  15340. - raw_spin_unlock(&pi_state->pi_mutex.wait_lock);
  15341. + raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
  15342. return ret;
  15343. }
  15344. - raw_spin_lock_irq(&pi_state->owner->pi_lock);
  15345. + raw_spin_lock(&pi_state->owner->pi_lock);
  15346. WARN_ON(list_empty(&pi_state->list));
  15347. list_del_init(&pi_state->list);
  15348. - raw_spin_unlock_irq(&pi_state->owner->pi_lock);
  15349. + raw_spin_unlock(&pi_state->owner->pi_lock);
  15350. - raw_spin_lock_irq(&new_owner->pi_lock);
  15351. + raw_spin_lock(&new_owner->pi_lock);
  15352. WARN_ON(!list_empty(&pi_state->list));
  15353. list_add(&pi_state->list, &new_owner->pi_state_list);
  15354. pi_state->owner = new_owner;
  15355. - raw_spin_unlock_irq(&new_owner->pi_lock);
  15356. + raw_spin_unlock(&new_owner->pi_lock);
  15357. - raw_spin_unlock(&pi_state->pi_mutex.wait_lock);
  15358. + raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
  15359. - deboost = rt_mutex_futex_unlock(&pi_state->pi_mutex, &wake_q);
  15360. + deboost = rt_mutex_futex_unlock(&pi_state->pi_mutex, &wake_q,
  15361. + &wake_sleeper_q);
  15362. /*
  15363. * First unlock HB so the waiter does not spin on it once he got woken
  15364. @@ -1286,6 +1290,7 @@
  15365. */
  15366. spin_unlock(&hb->lock);
  15367. wake_up_q(&wake_q);
  15368. + wake_up_q_sleeper(&wake_sleeper_q);
  15369. if (deboost)
  15370. rt_mutex_adjust_prio(current);
  15371. @@ -1822,6 +1827,16 @@
  15372. requeue_pi_wake_futex(this, &key2, hb2);
  15373. drop_count++;
  15374. continue;
  15375. + } else if (ret == -EAGAIN) {
  15376. + /*
  15377. + * Waiter was woken by timeout or
  15378. + * signal and has set pi_blocked_on to
  15379. + * PI_WAKEUP_INPROGRESS before we
  15380. + * tried to enqueue it on the rtmutex.
  15381. + */
  15382. + this->pi_state = NULL;
  15383. + free_pi_state(pi_state);
  15384. + continue;
  15385. } else if (ret) {
  15386. /* -EDEADLK */
  15387. this->pi_state = NULL;
  15388. @@ -2139,11 +2154,11 @@
  15389. * we returned due to timeout or signal without taking the
  15390. * rt_mutex. Too late.
  15391. */
  15392. - raw_spin_lock(&q->pi_state->pi_mutex.wait_lock);
  15393. + raw_spin_lock_irq(&q->pi_state->pi_mutex.wait_lock);
  15394. owner = rt_mutex_owner(&q->pi_state->pi_mutex);
  15395. if (!owner)
  15396. owner = rt_mutex_next_owner(&q->pi_state->pi_mutex);
  15397. - raw_spin_unlock(&q->pi_state->pi_mutex.wait_lock);
  15398. + raw_spin_unlock_irq(&q->pi_state->pi_mutex.wait_lock);
  15399. ret = fixup_pi_state_owner(uaddr, q, owner);
  15400. goto out;
  15401. }
  15402. @@ -2691,7 +2706,7 @@
  15403. struct hrtimer_sleeper timeout, *to = NULL;
  15404. struct rt_mutex_waiter rt_waiter;
  15405. struct rt_mutex *pi_mutex = NULL;
  15406. - struct futex_hash_bucket *hb;
  15407. + struct futex_hash_bucket *hb, *hb2;
  15408. union futex_key key2 = FUTEX_KEY_INIT;
  15409. struct futex_q q = futex_q_init;
  15410. int res, ret;
  15411. @@ -2716,10 +2731,7 @@
  15412. * The waiter is allocated on our stack, manipulated by the requeue
  15413. * code while we sleep on uaddr.
  15414. */
  15415. - debug_rt_mutex_init_waiter(&rt_waiter);
  15416. - RB_CLEAR_NODE(&rt_waiter.pi_tree_entry);
  15417. - RB_CLEAR_NODE(&rt_waiter.tree_entry);
  15418. - rt_waiter.task = NULL;
  15419. + rt_mutex_init_waiter(&rt_waiter, false);
  15420. ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, VERIFY_WRITE);
  15421. if (unlikely(ret != 0))
  15422. @@ -2750,20 +2762,55 @@
  15423. /* Queue the futex_q, drop the hb lock, wait for wakeup. */
  15424. futex_wait_queue_me(hb, &q, to);
  15425. - spin_lock(&hb->lock);
  15426. - ret = handle_early_requeue_pi_wakeup(hb, &q, &key2, to);
  15427. - spin_unlock(&hb->lock);
  15428. - if (ret)
  15429. - goto out_put_keys;
  15430. + /*
  15431. + * On RT we must avoid races with requeue and trying to block
  15432. + * on two mutexes (hb->lock and uaddr2's rtmutex) by
  15433. + * serializing access to pi_blocked_on with pi_lock.
  15434. + */
  15435. + raw_spin_lock_irq(&current->pi_lock);
  15436. + if (current->pi_blocked_on) {
  15437. + /*
  15438. + * We have been requeued or are in the process of
  15439. + * being requeued.
  15440. + */
  15441. + raw_spin_unlock_irq(&current->pi_lock);
  15442. + } else {
  15443. + /*
  15444. + * Setting pi_blocked_on to PI_WAKEUP_INPROGRESS
  15445. + * prevents a concurrent requeue from moving us to the
  15446. + * uaddr2 rtmutex. After that we can safely acquire
  15447. + * (and possibly block on) hb->lock.
  15448. + */
  15449. + current->pi_blocked_on = PI_WAKEUP_INPROGRESS;
  15450. + raw_spin_unlock_irq(&current->pi_lock);
  15451. +
  15452. + spin_lock(&hb->lock);
  15453. +
  15454. + /*
  15455. + * Clean up pi_blocked_on. We might leak it otherwise
  15456. + * when we succeeded with the hb->lock in the fast
  15457. + * path.
  15458. + */
  15459. + raw_spin_lock_irq(&current->pi_lock);
  15460. + current->pi_blocked_on = NULL;
  15461. + raw_spin_unlock_irq(&current->pi_lock);
  15462. +
  15463. + ret = handle_early_requeue_pi_wakeup(hb, &q, &key2, to);
  15464. + spin_unlock(&hb->lock);
  15465. + if (ret)
  15466. + goto out_put_keys;
  15467. + }
  15468. /*
  15469. - * In order for us to be here, we know our q.key == key2, and since
  15470. - * we took the hb->lock above, we also know that futex_requeue() has
  15471. - * completed and we no longer have to concern ourselves with a wakeup
  15472. - * race with the atomic proxy lock acquisition by the requeue code. The
  15473. - * futex_requeue dropped our key1 reference and incremented our key2
  15474. - * reference count.
  15475. + * In order to be here, we have either been requeued, are in
  15476. + * the process of being requeued, or requeue successfully
  15477. + * acquired uaddr2 on our behalf. If pi_blocked_on was
  15478. + * non-null above, we may be racing with a requeue. Do not
  15479. + * rely on q->lock_ptr to be hb2->lock until after blocking on
  15480. + * hb->lock or hb2->lock. The futex_requeue dropped our key1
  15481. + * reference and incremented our key2 reference count.
  15482. */
  15483. + hb2 = hash_futex(&key2);
  15484. /* Check if the requeue code acquired the second futex for us. */
  15485. if (!q.rt_waiter) {
  15486. @@ -2772,14 +2819,15 @@
  15487. * did a lock-steal - fix up the PI-state in that case.
  15488. */
  15489. if (q.pi_state && (q.pi_state->owner != current)) {
  15490. - spin_lock(q.lock_ptr);
  15491. + spin_lock(&hb2->lock);
  15492. + BUG_ON(&hb2->lock != q.lock_ptr);
  15493. ret = fixup_pi_state_owner(uaddr2, &q, current);
  15494. /*
  15495. * Drop the reference to the pi state which
  15496. * the requeue_pi() code acquired for us.
  15497. */
  15498. free_pi_state(q.pi_state);
  15499. - spin_unlock(q.lock_ptr);
  15500. + spin_unlock(&hb2->lock);
  15501. }
  15502. } else {
  15503. /*
  15504. @@ -2792,7 +2840,8 @@
  15505. ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter);
  15506. debug_rt_mutex_free_waiter(&rt_waiter);
  15507. - spin_lock(q.lock_ptr);
  15508. + spin_lock(&hb2->lock);
  15509. + BUG_ON(&hb2->lock != q.lock_ptr);
  15510. /*
  15511. * Fixup the pi_state owner and possibly acquire the lock if we
  15512. * haven't already.
  15513. diff -Nur linux-4.4.13.orig/kernel/irq/handle.c linux-4.4.13/kernel/irq/handle.c
  15514. --- linux-4.4.13.orig/kernel/irq/handle.c 2016-06-08 03:14:51.000000000 +0200
  15515. +++ linux-4.4.13/kernel/irq/handle.c 2016-06-22 21:55:08.046523867 +0200
  15516. @@ -134,6 +134,8 @@
  15517. irqreturn_t handle_irq_event_percpu(struct irq_desc *desc)
  15518. {
  15519. + struct pt_regs *regs = get_irq_regs();
  15520. + u64 ip = regs ? instruction_pointer(regs) : 0;
  15521. irqreturn_t retval = IRQ_NONE;
  15522. unsigned int flags = 0, irq = desc->irq_data.irq;
  15523. struct irqaction *action = desc->action;
  15524. @@ -176,7 +178,11 @@
  15525. action = action->next;
  15526. }
  15527. - add_interrupt_randomness(irq, flags);
  15528. +#ifdef CONFIG_PREEMPT_RT_FULL
  15529. + desc->random_ip = ip;
  15530. +#else
  15531. + add_interrupt_randomness(irq, flags, ip);
  15532. +#endif
  15533. if (!noirqdebug)
  15534. note_interrupt(desc, retval);
  15535. diff -Nur linux-4.4.13.orig/kernel/irq/irqdesc.c linux-4.4.13/kernel/irq/irqdesc.c
  15536. --- linux-4.4.13.orig/kernel/irq/irqdesc.c 2016-06-08 03:14:51.000000000 +0200
  15537. +++ linux-4.4.13/kernel/irq/irqdesc.c 2016-06-22 21:55:08.046523867 +0200
  15538. @@ -24,10 +24,27 @@
  15539. static struct lock_class_key irq_desc_lock_class;
  15540. #if defined(CONFIG_SMP)
  15541. +static int __init irq_affinity_setup(char *str)
  15542. +{
  15543. + zalloc_cpumask_var(&irq_default_affinity, GFP_NOWAIT);
  15544. + cpulist_parse(str, irq_default_affinity);
  15545. + /*
  15546. + * Set at least the boot cpu. We don't want to end up with
  15547. + * bugreports caused by random comandline masks
  15548. + */
  15549. + cpumask_set_cpu(smp_processor_id(), irq_default_affinity);
  15550. + return 1;
  15551. +}
  15552. +__setup("irqaffinity=", irq_affinity_setup);
  15553. +
  15554. static void __init init_irq_default_affinity(void)
  15555. {
  15556. - alloc_cpumask_var(&irq_default_affinity, GFP_NOWAIT);
  15557. - cpumask_setall(irq_default_affinity);
  15558. +#ifdef CONFIG_CPUMASK_OFFSTACK
  15559. + if (!irq_default_affinity)
  15560. + zalloc_cpumask_var(&irq_default_affinity, GFP_NOWAIT);
  15561. +#endif
  15562. + if (cpumask_empty(irq_default_affinity))
  15563. + cpumask_setall(irq_default_affinity);
  15564. }
  15565. #else
  15566. static void __init init_irq_default_affinity(void)
  15567. diff -Nur linux-4.4.13.orig/kernel/irq/manage.c linux-4.4.13/kernel/irq/manage.c
  15568. --- linux-4.4.13.orig/kernel/irq/manage.c 2016-06-08 03:14:51.000000000 +0200
  15569. +++ linux-4.4.13/kernel/irq/manage.c 2016-06-22 21:55:08.046523867 +0200
  15570. @@ -22,6 +22,7 @@
  15571. #include "internals.h"
  15572. #ifdef CONFIG_IRQ_FORCED_THREADING
  15573. +# ifndef CONFIG_PREEMPT_RT_BASE
  15574. __read_mostly bool force_irqthreads;
  15575. static int __init setup_forced_irqthreads(char *arg)
  15576. @@ -30,6 +31,7 @@
  15577. return 0;
  15578. }
  15579. early_param("threadirqs", setup_forced_irqthreads);
  15580. +# endif
  15581. #endif
  15582. static void __synchronize_hardirq(struct irq_desc *desc)
  15583. @@ -181,6 +183,62 @@
  15584. irq_get_pending(struct cpumask *mask, struct irq_desc *desc) { }
  15585. #endif
  15586. +#ifdef CONFIG_PREEMPT_RT_FULL
  15587. +static void _irq_affinity_notify(struct irq_affinity_notify *notify);
  15588. +static struct task_struct *set_affinity_helper;
  15589. +static LIST_HEAD(affinity_list);
  15590. +static DEFINE_RAW_SPINLOCK(affinity_list_lock);
  15591. +
  15592. +static int set_affinity_thread(void *unused)
  15593. +{
  15594. + while (1) {
  15595. + struct irq_affinity_notify *notify;
  15596. + int empty;
  15597. +
  15598. + set_current_state(TASK_INTERRUPTIBLE);
  15599. +
  15600. + raw_spin_lock_irq(&affinity_list_lock);
  15601. + empty = list_empty(&affinity_list);
  15602. + raw_spin_unlock_irq(&affinity_list_lock);
  15603. +
  15604. + if (empty)
  15605. + schedule();
  15606. + if (kthread_should_stop())
  15607. + break;
  15608. + set_current_state(TASK_RUNNING);
  15609. +try_next:
  15610. + notify = NULL;
  15611. +
  15612. + raw_spin_lock_irq(&affinity_list_lock);
  15613. + if (!list_empty(&affinity_list)) {
  15614. + notify = list_first_entry(&affinity_list,
  15615. + struct irq_affinity_notify, list);
  15616. + list_del_init(&notify->list);
  15617. + }
  15618. + raw_spin_unlock_irq(&affinity_list_lock);
  15619. +
  15620. + if (!notify)
  15621. + continue;
  15622. + _irq_affinity_notify(notify);
  15623. + goto try_next;
  15624. + }
  15625. + return 0;
  15626. +}
  15627. +
  15628. +static void init_helper_thread(void)
  15629. +{
  15630. + if (set_affinity_helper)
  15631. + return;
  15632. + set_affinity_helper = kthread_run(set_affinity_thread, NULL,
  15633. + "affinity-cb");
  15634. + WARN_ON(IS_ERR(set_affinity_helper));
  15635. +}
  15636. +#else
  15637. +
  15638. +static inline void init_helper_thread(void) { }
  15639. +
  15640. +#endif
  15641. +
  15642. int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask,
  15643. bool force)
  15644. {
  15645. @@ -220,7 +278,17 @@
  15646. if (desc->affinity_notify) {
  15647. kref_get(&desc->affinity_notify->kref);
  15648. +
  15649. +#ifdef CONFIG_PREEMPT_RT_FULL
  15650. + raw_spin_lock(&affinity_list_lock);
  15651. + if (list_empty(&desc->affinity_notify->list))
  15652. + list_add_tail(&affinity_list,
  15653. + &desc->affinity_notify->list);
  15654. + raw_spin_unlock(&affinity_list_lock);
  15655. + wake_up_process(set_affinity_helper);
  15656. +#else
  15657. schedule_work(&desc->affinity_notify->work);
  15658. +#endif
  15659. }
  15660. irqd_set(data, IRQD_AFFINITY_SET);
  15661. @@ -258,10 +326,8 @@
  15662. }
  15663. EXPORT_SYMBOL_GPL(irq_set_affinity_hint);
  15664. -static void irq_affinity_notify(struct work_struct *work)
  15665. +static void _irq_affinity_notify(struct irq_affinity_notify *notify)
  15666. {
  15667. - struct irq_affinity_notify *notify =
  15668. - container_of(work, struct irq_affinity_notify, work);
  15669. struct irq_desc *desc = irq_to_desc(notify->irq);
  15670. cpumask_var_t cpumask;
  15671. unsigned long flags;
  15672. @@ -283,6 +349,13 @@
  15673. kref_put(&notify->kref, notify->release);
  15674. }
  15675. +static void irq_affinity_notify(struct work_struct *work)
  15676. +{
  15677. + struct irq_affinity_notify *notify =
  15678. + container_of(work, struct irq_affinity_notify, work);
  15679. + _irq_affinity_notify(notify);
  15680. +}
  15681. +
  15682. /**
  15683. * irq_set_affinity_notifier - control notification of IRQ affinity changes
  15684. * @irq: Interrupt for which to enable/disable notification
  15685. @@ -312,6 +385,8 @@
  15686. notify->irq = irq;
  15687. kref_init(&notify->kref);
  15688. INIT_WORK(&notify->work, irq_affinity_notify);
  15689. + INIT_LIST_HEAD(&notify->list);
  15690. + init_helper_thread();
  15691. }
  15692. raw_spin_lock_irqsave(&desc->lock, flags);
  15693. @@ -865,7 +940,15 @@
  15694. local_bh_disable();
  15695. ret = action->thread_fn(action->irq, action->dev_id);
  15696. irq_finalize_oneshot(desc, action);
  15697. - local_bh_enable();
  15698. + /*
  15699. + * Interrupts which have real time requirements can be set up
  15700. + * to avoid softirq processing in the thread handler. This is
  15701. + * safe as these interrupts do not raise soft interrupts.
  15702. + */
  15703. + if (irq_settings_no_softirq_call(desc))
  15704. + _local_bh_enable();
  15705. + else
  15706. + local_bh_enable();
  15707. return ret;
  15708. }
  15709. @@ -962,6 +1045,12 @@
  15710. if (action_ret == IRQ_WAKE_THREAD)
  15711. irq_wake_secondary(desc, action);
  15712. +#ifdef CONFIG_PREEMPT_RT_FULL
  15713. + migrate_disable();
  15714. + add_interrupt_randomness(action->irq, 0,
  15715. + desc->random_ip ^ (unsigned long) action);
  15716. + migrate_enable();
  15717. +#endif
  15718. wake_threads_waitq(desc);
  15719. }
  15720. @@ -1315,6 +1404,9 @@
  15721. irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
  15722. }
  15723. + if (new->flags & IRQF_NO_SOFTIRQ_CALL)
  15724. + irq_settings_set_no_softirq_call(desc);
  15725. +
  15726. /* Set default affinity mask once everything is setup */
  15727. setup_affinity(desc, mask);
  15728. @@ -1968,7 +2060,7 @@
  15729. * This call sets the internal irqchip state of an interrupt,
  15730. * depending on the value of @which.
  15731. *
  15732. - * This function should be called with preemption disabled if the
  15733. + * This function should be called with migration disabled if the
  15734. * interrupt controller has per-cpu registers.
  15735. */
  15736. int irq_set_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
  15737. diff -Nur linux-4.4.13.orig/kernel/irq/settings.h linux-4.4.13/kernel/irq/settings.h
  15738. --- linux-4.4.13.orig/kernel/irq/settings.h 2016-06-08 03:14:51.000000000 +0200
  15739. +++ linux-4.4.13/kernel/irq/settings.h 2016-06-22 21:55:08.046523867 +0200
  15740. @@ -16,6 +16,7 @@
  15741. _IRQ_PER_CPU_DEVID = IRQ_PER_CPU_DEVID,
  15742. _IRQ_IS_POLLED = IRQ_IS_POLLED,
  15743. _IRQ_DISABLE_UNLAZY = IRQ_DISABLE_UNLAZY,
  15744. + _IRQ_NO_SOFTIRQ_CALL = IRQ_NO_SOFTIRQ_CALL,
  15745. _IRQF_MODIFY_MASK = IRQF_MODIFY_MASK,
  15746. };
  15747. @@ -30,6 +31,7 @@
  15748. #define IRQ_PER_CPU_DEVID GOT_YOU_MORON
  15749. #define IRQ_IS_POLLED GOT_YOU_MORON
  15750. #define IRQ_DISABLE_UNLAZY GOT_YOU_MORON
  15751. +#define IRQ_NO_SOFTIRQ_CALL GOT_YOU_MORON
  15752. #undef IRQF_MODIFY_MASK
  15753. #define IRQF_MODIFY_MASK GOT_YOU_MORON
  15754. @@ -40,6 +42,16 @@
  15755. desc->status_use_accessors |= (set & _IRQF_MODIFY_MASK);
  15756. }
  15757. +static inline bool irq_settings_no_softirq_call(struct irq_desc *desc)
  15758. +{
  15759. + return desc->status_use_accessors & _IRQ_NO_SOFTIRQ_CALL;
  15760. +}
  15761. +
  15762. +static inline void irq_settings_set_no_softirq_call(struct irq_desc *desc)
  15763. +{
  15764. + desc->status_use_accessors |= _IRQ_NO_SOFTIRQ_CALL;
  15765. +}
  15766. +
  15767. static inline bool irq_settings_is_per_cpu(struct irq_desc *desc)
  15768. {
  15769. return desc->status_use_accessors & _IRQ_PER_CPU;
  15770. diff -Nur linux-4.4.13.orig/kernel/irq/spurious.c linux-4.4.13/kernel/irq/spurious.c
  15771. --- linux-4.4.13.orig/kernel/irq/spurious.c 2016-06-08 03:14:51.000000000 +0200
  15772. +++ linux-4.4.13/kernel/irq/spurious.c 2016-06-22 21:55:08.050523867 +0200
  15773. @@ -444,6 +444,10 @@
  15774. static int __init irqfixup_setup(char *str)
  15775. {
  15776. +#ifdef CONFIG_PREEMPT_RT_BASE
  15777. + pr_warn("irqfixup boot option not supported w/ CONFIG_PREEMPT_RT_BASE\n");
  15778. + return 1;
  15779. +#endif
  15780. irqfixup = 1;
  15781. printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
  15782. printk(KERN_WARNING "This may impact system performance.\n");
  15783. @@ -456,6 +460,10 @@
  15784. static int __init irqpoll_setup(char *str)
  15785. {
  15786. +#ifdef CONFIG_PREEMPT_RT_BASE
  15787. + pr_warn("irqpoll boot option not supported w/ CONFIG_PREEMPT_RT_BASE\n");
  15788. + return 1;
  15789. +#endif
  15790. irqfixup = 2;
  15791. printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
  15792. "enabled\n");
  15793. diff -Nur linux-4.4.13.orig/kernel/irq_work.c linux-4.4.13/kernel/irq_work.c
  15794. --- linux-4.4.13.orig/kernel/irq_work.c 2016-06-08 03:14:51.000000000 +0200
  15795. +++ linux-4.4.13/kernel/irq_work.c 2016-06-22 21:55:08.050523867 +0200
  15796. @@ -17,6 +17,7 @@
  15797. #include <linux/cpu.h>
  15798. #include <linux/notifier.h>
  15799. #include <linux/smp.h>
  15800. +#include <linux/interrupt.h>
  15801. #include <asm/processor.h>
  15802. @@ -65,6 +66,8 @@
  15803. */
  15804. bool irq_work_queue_on(struct irq_work *work, int cpu)
  15805. {
  15806. + struct llist_head *list;
  15807. +
  15808. /* All work should have been flushed before going offline */
  15809. WARN_ON_ONCE(cpu_is_offline(cpu));
  15810. @@ -75,7 +78,12 @@
  15811. if (!irq_work_claim(work))
  15812. return false;
  15813. - if (llist_add(&work->llnode, &per_cpu(raised_list, cpu)))
  15814. + if (IS_ENABLED(CONFIG_PREEMPT_RT_FULL) && !(work->flags & IRQ_WORK_HARD_IRQ))
  15815. + list = &per_cpu(lazy_list, cpu);
  15816. + else
  15817. + list = &per_cpu(raised_list, cpu);
  15818. +
  15819. + if (llist_add(&work->llnode, list))
  15820. arch_send_call_function_single_ipi(cpu);
  15821. return true;
  15822. @@ -86,6 +94,9 @@
  15823. /* Enqueue the irq work @work on the current CPU */
  15824. bool irq_work_queue(struct irq_work *work)
  15825. {
  15826. + struct llist_head *list;
  15827. + bool lazy_work, realtime = IS_ENABLED(CONFIG_PREEMPT_RT_FULL);
  15828. +
  15829. /* Only queue if not already pending */
  15830. if (!irq_work_claim(work))
  15831. return false;
  15832. @@ -93,13 +104,15 @@
  15833. /* Queue the entry and raise the IPI if needed. */
  15834. preempt_disable();
  15835. - /* If the work is "lazy", handle it from next tick if any */
  15836. - if (work->flags & IRQ_WORK_LAZY) {
  15837. - if (llist_add(&work->llnode, this_cpu_ptr(&lazy_list)) &&
  15838. - tick_nohz_tick_stopped())
  15839. - arch_irq_work_raise();
  15840. - } else {
  15841. - if (llist_add(&work->llnode, this_cpu_ptr(&raised_list)))
  15842. + lazy_work = work->flags & IRQ_WORK_LAZY;
  15843. +
  15844. + if (lazy_work || (realtime && !(work->flags & IRQ_WORK_HARD_IRQ)))
  15845. + list = this_cpu_ptr(&lazy_list);
  15846. + else
  15847. + list = this_cpu_ptr(&raised_list);
  15848. +
  15849. + if (llist_add(&work->llnode, list)) {
  15850. + if (!lazy_work || tick_nohz_tick_stopped())
  15851. arch_irq_work_raise();
  15852. }
  15853. @@ -116,9 +129,8 @@
  15854. raised = this_cpu_ptr(&raised_list);
  15855. lazy = this_cpu_ptr(&lazy_list);
  15856. - if (llist_empty(raised) || arch_irq_work_has_interrupt())
  15857. - if (llist_empty(lazy))
  15858. - return false;
  15859. + if (llist_empty(raised) && llist_empty(lazy))
  15860. + return false;
  15861. /* All work should have been flushed before going offline */
  15862. WARN_ON_ONCE(cpu_is_offline(smp_processor_id()));
  15863. @@ -132,7 +144,7 @@
  15864. struct irq_work *work;
  15865. struct llist_node *llnode;
  15866. - BUG_ON(!irqs_disabled());
  15867. + BUG_ON_NONRT(!irqs_disabled());
  15868. if (llist_empty(list))
  15869. return;
  15870. @@ -169,7 +181,16 @@
  15871. void irq_work_run(void)
  15872. {
  15873. irq_work_run_list(this_cpu_ptr(&raised_list));
  15874. - irq_work_run_list(this_cpu_ptr(&lazy_list));
  15875. + if (IS_ENABLED(CONFIG_PREEMPT_RT_FULL)) {
  15876. + /*
  15877. + * NOTE: we raise softirq via IPI for safety,
  15878. + * and execute in irq_work_tick() to move the
  15879. + * overhead from hard to soft irq context.
  15880. + */
  15881. + if (!llist_empty(this_cpu_ptr(&lazy_list)))
  15882. + raise_softirq(TIMER_SOFTIRQ);
  15883. + } else
  15884. + irq_work_run_list(this_cpu_ptr(&lazy_list));
  15885. }
  15886. EXPORT_SYMBOL_GPL(irq_work_run);
  15887. @@ -179,8 +200,17 @@
  15888. if (!llist_empty(raised) && !arch_irq_work_has_interrupt())
  15889. irq_work_run_list(raised);
  15890. +
  15891. + if (!IS_ENABLED(CONFIG_PREEMPT_RT_FULL))
  15892. + irq_work_run_list(this_cpu_ptr(&lazy_list));
  15893. +}
  15894. +
  15895. +#if defined(CONFIG_IRQ_WORK) && defined(CONFIG_PREEMPT_RT_FULL)
  15896. +void irq_work_tick_soft(void)
  15897. +{
  15898. irq_work_run_list(this_cpu_ptr(&lazy_list));
  15899. }
  15900. +#endif
  15901. /*
  15902. * Synchronize against the irq_work @entry, ensures the entry is not
  15903. diff -Nur linux-4.4.13.orig/kernel/Kconfig.locks linux-4.4.13/kernel/Kconfig.locks
  15904. --- linux-4.4.13.orig/kernel/Kconfig.locks 2016-06-08 03:14:51.000000000 +0200
  15905. +++ linux-4.4.13/kernel/Kconfig.locks 2016-06-22 21:55:08.050523867 +0200
  15906. @@ -225,11 +225,11 @@
  15907. config MUTEX_SPIN_ON_OWNER
  15908. def_bool y
  15909. - depends on SMP && !DEBUG_MUTEXES && ARCH_SUPPORTS_ATOMIC_RMW
  15910. + depends on SMP && !DEBUG_MUTEXES && ARCH_SUPPORTS_ATOMIC_RMW && !PREEMPT_RT_FULL
  15911. config RWSEM_SPIN_ON_OWNER
  15912. def_bool y
  15913. - depends on SMP && RWSEM_XCHGADD_ALGORITHM && ARCH_SUPPORTS_ATOMIC_RMW
  15914. + depends on SMP && RWSEM_XCHGADD_ALGORITHM && ARCH_SUPPORTS_ATOMIC_RMW && !PREEMPT_RT_FULL
  15915. config LOCK_SPIN_ON_OWNER
  15916. def_bool y
  15917. diff -Nur linux-4.4.13.orig/kernel/Kconfig.preempt linux-4.4.13/kernel/Kconfig.preempt
  15918. --- linux-4.4.13.orig/kernel/Kconfig.preempt 2016-06-08 03:14:51.000000000 +0200
  15919. +++ linux-4.4.13/kernel/Kconfig.preempt 2016-06-22 21:55:08.050523867 +0200
  15920. @@ -1,3 +1,16 @@
  15921. +config PREEMPT
  15922. + bool
  15923. + select PREEMPT_COUNT
  15924. +
  15925. +config PREEMPT_RT_BASE
  15926. + bool
  15927. + select PREEMPT
  15928. +
  15929. +config HAVE_PREEMPT_LAZY
  15930. + bool
  15931. +
  15932. +config PREEMPT_LAZY
  15933. + def_bool y if HAVE_PREEMPT_LAZY && PREEMPT_RT_FULL
  15934. choice
  15935. prompt "Preemption Model"
  15936. @@ -33,9 +46,9 @@
  15937. Select this if you are building a kernel for a desktop system.
  15938. -config PREEMPT
  15939. +config PREEMPT__LL
  15940. bool "Preemptible Kernel (Low-Latency Desktop)"
  15941. - select PREEMPT_COUNT
  15942. + select PREEMPT
  15943. select UNINLINE_SPIN_UNLOCK if !ARCH_INLINE_SPIN_UNLOCK
  15944. help
  15945. This option reduces the latency of the kernel by making
  15946. @@ -52,6 +65,22 @@
  15947. embedded system with latency requirements in the milliseconds
  15948. range.
  15949. +config PREEMPT_RTB
  15950. + bool "Preemptible Kernel (Basic RT)"
  15951. + select PREEMPT_RT_BASE
  15952. + help
  15953. + This option is basically the same as (Low-Latency Desktop) but
  15954. + enables changes which are preliminary for the full preemptible
  15955. + RT kernel.
  15956. +
  15957. +config PREEMPT_RT_FULL
  15958. + bool "Fully Preemptible Kernel (RT)"
  15959. + depends on IRQ_FORCED_THREADING
  15960. + select PREEMPT_RT_BASE
  15961. + select PREEMPT_RCU
  15962. + help
  15963. + All and everything
  15964. +
  15965. endchoice
  15966. config PREEMPT_COUNT
  15967. diff -Nur linux-4.4.13.orig/kernel/ksysfs.c linux-4.4.13/kernel/ksysfs.c
  15968. --- linux-4.4.13.orig/kernel/ksysfs.c 2016-06-08 03:14:51.000000000 +0200
  15969. +++ linux-4.4.13/kernel/ksysfs.c 2016-06-22 21:55:08.050523867 +0200
  15970. @@ -136,6 +136,15 @@
  15971. #endif /* CONFIG_KEXEC_CORE */
  15972. +#if defined(CONFIG_PREEMPT_RT_FULL)
  15973. +static ssize_t realtime_show(struct kobject *kobj,
  15974. + struct kobj_attribute *attr, char *buf)
  15975. +{
  15976. + return sprintf(buf, "%d\n", 1);
  15977. +}
  15978. +KERNEL_ATTR_RO(realtime);
  15979. +#endif
  15980. +
  15981. /* whether file capabilities are enabled */
  15982. static ssize_t fscaps_show(struct kobject *kobj,
  15983. struct kobj_attribute *attr, char *buf)
  15984. @@ -203,6 +212,9 @@
  15985. &vmcoreinfo_attr.attr,
  15986. #endif
  15987. &rcu_expedited_attr.attr,
  15988. +#ifdef CONFIG_PREEMPT_RT_FULL
  15989. + &realtime_attr.attr,
  15990. +#endif
  15991. NULL
  15992. };
  15993. diff -Nur linux-4.4.13.orig/kernel/locking/lglock.c linux-4.4.13/kernel/locking/lglock.c
  15994. --- linux-4.4.13.orig/kernel/locking/lglock.c 2016-06-08 03:14:51.000000000 +0200
  15995. +++ linux-4.4.13/kernel/locking/lglock.c 2016-06-22 21:55:08.050523867 +0200
  15996. @@ -4,6 +4,15 @@
  15997. #include <linux/cpu.h>
  15998. #include <linux/string.h>
  15999. +#ifndef CONFIG_PREEMPT_RT_FULL
  16000. +# define lg_lock_ptr arch_spinlock_t
  16001. +# define lg_do_lock(l) arch_spin_lock(l)
  16002. +# define lg_do_unlock(l) arch_spin_unlock(l)
  16003. +#else
  16004. +# define lg_lock_ptr struct rt_mutex
  16005. +# define lg_do_lock(l) __rt_spin_lock__no_mg(l)
  16006. +# define lg_do_unlock(l) __rt_spin_unlock(l)
  16007. +#endif
  16008. /*
  16009. * Note there is no uninit, so lglocks cannot be defined in
  16010. * modules (but it's fine to use them from there)
  16011. @@ -12,51 +21,60 @@
  16012. void lg_lock_init(struct lglock *lg, char *name)
  16013. {
  16014. +#ifdef CONFIG_PREEMPT_RT_FULL
  16015. + int i;
  16016. +
  16017. + for_each_possible_cpu(i) {
  16018. + struct rt_mutex *lock = per_cpu_ptr(lg->lock, i);
  16019. +
  16020. + rt_mutex_init(lock);
  16021. + }
  16022. +#endif
  16023. LOCKDEP_INIT_MAP(&lg->lock_dep_map, name, &lg->lock_key, 0);
  16024. }
  16025. EXPORT_SYMBOL(lg_lock_init);
  16026. void lg_local_lock(struct lglock *lg)
  16027. {
  16028. - arch_spinlock_t *lock;
  16029. + lg_lock_ptr *lock;
  16030. - preempt_disable();
  16031. + migrate_disable();
  16032. lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  16033. lock = this_cpu_ptr(lg->lock);
  16034. - arch_spin_lock(lock);
  16035. + lg_do_lock(lock);
  16036. }
  16037. EXPORT_SYMBOL(lg_local_lock);
  16038. void lg_local_unlock(struct lglock *lg)
  16039. {
  16040. - arch_spinlock_t *lock;
  16041. + lg_lock_ptr *lock;
  16042. lock_release(&lg->lock_dep_map, 1, _RET_IP_);
  16043. lock = this_cpu_ptr(lg->lock);
  16044. - arch_spin_unlock(lock);
  16045. - preempt_enable();
  16046. + lg_do_unlock(lock);
  16047. + migrate_enable();
  16048. }
  16049. EXPORT_SYMBOL(lg_local_unlock);
  16050. void lg_local_lock_cpu(struct lglock *lg, int cpu)
  16051. {
  16052. - arch_spinlock_t *lock;
  16053. + lg_lock_ptr *lock;
  16054. - preempt_disable();
  16055. + preempt_disable_nort();
  16056. lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  16057. lock = per_cpu_ptr(lg->lock, cpu);
  16058. - arch_spin_lock(lock);
  16059. + lg_do_lock(lock);
  16060. }
  16061. EXPORT_SYMBOL(lg_local_lock_cpu);
  16062. void lg_local_unlock_cpu(struct lglock *lg, int cpu)
  16063. {
  16064. - arch_spinlock_t *lock;
  16065. + lg_lock_ptr *lock;
  16066. lock_release(&lg->lock_dep_map, 1, _RET_IP_);
  16067. lock = per_cpu_ptr(lg->lock, cpu);
  16068. - arch_spin_unlock(lock);
  16069. - preempt_enable();
  16070. + lg_do_unlock(lock);
  16071. + preempt_enable_nort();
  16072. }
  16073. EXPORT_SYMBOL(lg_local_unlock_cpu);
  16074. @@ -68,30 +86,30 @@
  16075. if (cpu2 < cpu1)
  16076. swap(cpu1, cpu2);
  16077. - preempt_disable();
  16078. + preempt_disable_nort();
  16079. lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  16080. - arch_spin_lock(per_cpu_ptr(lg->lock, cpu1));
  16081. - arch_spin_lock(per_cpu_ptr(lg->lock, cpu2));
  16082. + lg_do_lock(per_cpu_ptr(lg->lock, cpu1));
  16083. + lg_do_lock(per_cpu_ptr(lg->lock, cpu2));
  16084. }
  16085. void lg_double_unlock(struct lglock *lg, int cpu1, int cpu2)
  16086. {
  16087. lock_release(&lg->lock_dep_map, 1, _RET_IP_);
  16088. - arch_spin_unlock(per_cpu_ptr(lg->lock, cpu1));
  16089. - arch_spin_unlock(per_cpu_ptr(lg->lock, cpu2));
  16090. - preempt_enable();
  16091. + lg_do_unlock(per_cpu_ptr(lg->lock, cpu1));
  16092. + lg_do_unlock(per_cpu_ptr(lg->lock, cpu2));
  16093. + preempt_enable_nort();
  16094. }
  16095. void lg_global_lock(struct lglock *lg)
  16096. {
  16097. int i;
  16098. - preempt_disable();
  16099. + preempt_disable_nort();
  16100. lock_acquire_exclusive(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  16101. for_each_possible_cpu(i) {
  16102. - arch_spinlock_t *lock;
  16103. + lg_lock_ptr *lock;
  16104. lock = per_cpu_ptr(lg->lock, i);
  16105. - arch_spin_lock(lock);
  16106. + lg_do_lock(lock);
  16107. }
  16108. }
  16109. EXPORT_SYMBOL(lg_global_lock);
  16110. @@ -102,10 +120,35 @@
  16111. lock_release(&lg->lock_dep_map, 1, _RET_IP_);
  16112. for_each_possible_cpu(i) {
  16113. - arch_spinlock_t *lock;
  16114. + lg_lock_ptr *lock;
  16115. lock = per_cpu_ptr(lg->lock, i);
  16116. - arch_spin_unlock(lock);
  16117. + lg_do_unlock(lock);
  16118. }
  16119. - preempt_enable();
  16120. + preempt_enable_nort();
  16121. }
  16122. EXPORT_SYMBOL(lg_global_unlock);
  16123. +
  16124. +#ifdef CONFIG_PREEMPT_RT_FULL
  16125. +/*
  16126. + * HACK: If you use this, you get to keep the pieces.
  16127. + * Used in queue_stop_cpus_work() when stop machinery
  16128. + * is called from inactive CPU, so we can't schedule.
  16129. + */
  16130. +# define lg_do_trylock_relax(l) \
  16131. + do { \
  16132. + while (!__rt_spin_trylock(l)) \
  16133. + cpu_relax(); \
  16134. + } while (0)
  16135. +
  16136. +void lg_global_trylock_relax(struct lglock *lg)
  16137. +{
  16138. + int i;
  16139. +
  16140. + lock_acquire_exclusive(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  16141. + for_each_possible_cpu(i) {
  16142. + lg_lock_ptr *lock;
  16143. + lock = per_cpu_ptr(lg->lock, i);
  16144. + lg_do_trylock_relax(lock);
  16145. + }
  16146. +}
  16147. +#endif
  16148. diff -Nur linux-4.4.13.orig/kernel/locking/lockdep.c linux-4.4.13/kernel/locking/lockdep.c
  16149. --- linux-4.4.13.orig/kernel/locking/lockdep.c 2016-06-08 03:14:51.000000000 +0200
  16150. +++ linux-4.4.13/kernel/locking/lockdep.c 2016-06-22 21:55:08.050523867 +0200
  16151. @@ -3525,6 +3525,7 @@
  16152. }
  16153. }
  16154. +#ifndef CONFIG_PREEMPT_RT_FULL
  16155. /*
  16156. * We dont accurately track softirq state in e.g.
  16157. * hardirq contexts (such as on 4KSTACKS), so only
  16158. @@ -3539,6 +3540,7 @@
  16159. DEBUG_LOCKS_WARN_ON(!current->softirqs_enabled);
  16160. }
  16161. }
  16162. +#endif
  16163. if (!debug_locks)
  16164. print_irqtrace_events(current);
  16165. diff -Nur linux-4.4.13.orig/kernel/locking/locktorture.c linux-4.4.13/kernel/locking/locktorture.c
  16166. --- linux-4.4.13.orig/kernel/locking/locktorture.c 2016-06-08 03:14:51.000000000 +0200
  16167. +++ linux-4.4.13/kernel/locking/locktorture.c 2016-06-22 21:55:08.050523867 +0200
  16168. @@ -26,7 +26,6 @@
  16169. #include <linux/kthread.h>
  16170. #include <linux/sched/rt.h>
  16171. #include <linux/spinlock.h>
  16172. -#include <linux/rwlock.h>
  16173. #include <linux/mutex.h>
  16174. #include <linux/rwsem.h>
  16175. #include <linux/smp.h>
  16176. diff -Nur linux-4.4.13.orig/kernel/locking/Makefile linux-4.4.13/kernel/locking/Makefile
  16177. --- linux-4.4.13.orig/kernel/locking/Makefile 2016-06-08 03:14:51.000000000 +0200
  16178. +++ linux-4.4.13/kernel/locking/Makefile 2016-06-22 21:55:08.050523867 +0200
  16179. @@ -1,5 +1,5 @@
  16180. -obj-y += mutex.o semaphore.o rwsem.o percpu-rwsem.o
  16181. +obj-y += semaphore.o percpu-rwsem.o
  16182. ifdef CONFIG_FUNCTION_TRACER
  16183. CFLAGS_REMOVE_lockdep.o = $(CC_FLAGS_FTRACE)
  16184. @@ -8,7 +8,11 @@
  16185. CFLAGS_REMOVE_rtmutex-debug.o = $(CC_FLAGS_FTRACE)
  16186. endif
  16187. +ifneq ($(CONFIG_PREEMPT_RT_FULL),y)
  16188. +obj-y += mutex.o
  16189. obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
  16190. +obj-y += rwsem.o
  16191. +endif
  16192. obj-$(CONFIG_LOCKDEP) += lockdep.o
  16193. ifeq ($(CONFIG_PROC_FS),y)
  16194. obj-$(CONFIG_LOCKDEP) += lockdep_proc.o
  16195. @@ -22,7 +26,10 @@
  16196. obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o
  16197. obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
  16198. obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o
  16199. +ifneq ($(CONFIG_PREEMPT_RT_FULL),y)
  16200. obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
  16201. obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem-xadd.o
  16202. +endif
  16203. +obj-$(CONFIG_PREEMPT_RT_FULL) += rt.o
  16204. obj-$(CONFIG_QUEUED_RWLOCKS) += qrwlock.o
  16205. obj-$(CONFIG_LOCK_TORTURE_TEST) += locktorture.o
  16206. diff -Nur linux-4.4.13.orig/kernel/locking/rt.c linux-4.4.13/kernel/locking/rt.c
  16207. --- linux-4.4.13.orig/kernel/locking/rt.c 1970-01-01 01:00:00.000000000 +0100
  16208. +++ linux-4.4.13/kernel/locking/rt.c 2016-06-22 21:55:08.050523867 +0200
  16209. @@ -0,0 +1,474 @@
  16210. +/*
  16211. + * kernel/rt.c
  16212. + *
  16213. + * Real-Time Preemption Support
  16214. + *
  16215. + * started by Ingo Molnar:
  16216. + *
  16217. + * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  16218. + * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  16219. + *
  16220. + * historic credit for proving that Linux spinlocks can be implemented via
  16221. + * RT-aware mutexes goes to many people: The Pmutex project (Dirk Grambow
  16222. + * and others) who prototyped it on 2.4 and did lots of comparative
  16223. + * research and analysis; TimeSys, for proving that you can implement a
  16224. + * fully preemptible kernel via the use of IRQ threading and mutexes;
  16225. + * Bill Huey for persuasively arguing on lkml that the mutex model is the
  16226. + * right one; and to MontaVista, who ported pmutexes to 2.6.
  16227. + *
  16228. + * This code is a from-scratch implementation and is not based on pmutexes,
  16229. + * but the idea of converting spinlocks to mutexes is used here too.
  16230. + *
  16231. + * lock debugging, locking tree, deadlock detection:
  16232. + *
  16233. + * Copyright (C) 2004, LynuxWorks, Inc., Igor Manyilov, Bill Huey
  16234. + * Released under the General Public License (GPL).
  16235. + *
  16236. + * Includes portions of the generic R/W semaphore implementation from:
  16237. + *
  16238. + * Copyright (c) 2001 David Howells (dhowells@redhat.com).
  16239. + * - Derived partially from idea by Andrea Arcangeli <andrea@suse.de>
  16240. + * - Derived also from comments by Linus
  16241. + *
  16242. + * Pending ownership of locks and ownership stealing:
  16243. + *
  16244. + * Copyright (C) 2005, Kihon Technologies Inc., Steven Rostedt
  16245. + *
  16246. + * (also by Steven Rostedt)
  16247. + * - Converted single pi_lock to individual task locks.
  16248. + *
  16249. + * By Esben Nielsen:
  16250. + * Doing priority inheritance with help of the scheduler.
  16251. + *
  16252. + * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  16253. + * - major rework based on Esben Nielsens initial patch
  16254. + * - replaced thread_info references by task_struct refs
  16255. + * - removed task->pending_owner dependency
  16256. + * - BKL drop/reacquire for semaphore style locks to avoid deadlocks
  16257. + * in the scheduler return path as discussed with Steven Rostedt
  16258. + *
  16259. + * Copyright (C) 2006, Kihon Technologies Inc.
  16260. + * Steven Rostedt <rostedt@goodmis.org>
  16261. + * - debugged and patched Thomas Gleixner's rework.
  16262. + * - added back the cmpxchg to the rework.
  16263. + * - turned atomic require back on for SMP.
  16264. + */
  16265. +
  16266. +#include <linux/spinlock.h>
  16267. +#include <linux/rtmutex.h>
  16268. +#include <linux/sched.h>
  16269. +#include <linux/delay.h>
  16270. +#include <linux/module.h>
  16271. +#include <linux/kallsyms.h>
  16272. +#include <linux/syscalls.h>
  16273. +#include <linux/interrupt.h>
  16274. +#include <linux/plist.h>
  16275. +#include <linux/fs.h>
  16276. +#include <linux/futex.h>
  16277. +#include <linux/hrtimer.h>
  16278. +
  16279. +#include "rtmutex_common.h"
  16280. +
  16281. +/*
  16282. + * struct mutex functions
  16283. + */
  16284. +void __mutex_do_init(struct mutex *mutex, const char *name,
  16285. + struct lock_class_key *key)
  16286. +{
  16287. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  16288. + /*
  16289. + * Make sure we are not reinitializing a held lock:
  16290. + */
  16291. + debug_check_no_locks_freed((void *)mutex, sizeof(*mutex));
  16292. + lockdep_init_map(&mutex->dep_map, name, key, 0);
  16293. +#endif
  16294. + mutex->lock.save_state = 0;
  16295. +}
  16296. +EXPORT_SYMBOL(__mutex_do_init);
  16297. +
  16298. +void __lockfunc _mutex_lock(struct mutex *lock)
  16299. +{
  16300. + mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  16301. + rt_mutex_lock(&lock->lock);
  16302. +}
  16303. +EXPORT_SYMBOL(_mutex_lock);
  16304. +
  16305. +int __lockfunc _mutex_lock_interruptible(struct mutex *lock)
  16306. +{
  16307. + int ret;
  16308. +
  16309. + mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  16310. + ret = rt_mutex_lock_interruptible(&lock->lock);
  16311. + if (ret)
  16312. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  16313. + return ret;
  16314. +}
  16315. +EXPORT_SYMBOL(_mutex_lock_interruptible);
  16316. +
  16317. +int __lockfunc _mutex_lock_killable(struct mutex *lock)
  16318. +{
  16319. + int ret;
  16320. +
  16321. + mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  16322. + ret = rt_mutex_lock_killable(&lock->lock);
  16323. + if (ret)
  16324. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  16325. + return ret;
  16326. +}
  16327. +EXPORT_SYMBOL(_mutex_lock_killable);
  16328. +
  16329. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  16330. +void __lockfunc _mutex_lock_nested(struct mutex *lock, int subclass)
  16331. +{
  16332. + mutex_acquire_nest(&lock->dep_map, subclass, 0, NULL, _RET_IP_);
  16333. + rt_mutex_lock(&lock->lock);
  16334. +}
  16335. +EXPORT_SYMBOL(_mutex_lock_nested);
  16336. +
  16337. +void __lockfunc _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest)
  16338. +{
  16339. + mutex_acquire_nest(&lock->dep_map, 0, 0, nest, _RET_IP_);
  16340. + rt_mutex_lock(&lock->lock);
  16341. +}
  16342. +EXPORT_SYMBOL(_mutex_lock_nest_lock);
  16343. +
  16344. +int __lockfunc _mutex_lock_interruptible_nested(struct mutex *lock, int subclass)
  16345. +{
  16346. + int ret;
  16347. +
  16348. + mutex_acquire_nest(&lock->dep_map, subclass, 0, NULL, _RET_IP_);
  16349. + ret = rt_mutex_lock_interruptible(&lock->lock);
  16350. + if (ret)
  16351. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  16352. + return ret;
  16353. +}
  16354. +EXPORT_SYMBOL(_mutex_lock_interruptible_nested);
  16355. +
  16356. +int __lockfunc _mutex_lock_killable_nested(struct mutex *lock, int subclass)
  16357. +{
  16358. + int ret;
  16359. +
  16360. + mutex_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
  16361. + ret = rt_mutex_lock_killable(&lock->lock);
  16362. + if (ret)
  16363. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  16364. + return ret;
  16365. +}
  16366. +EXPORT_SYMBOL(_mutex_lock_killable_nested);
  16367. +#endif
  16368. +
  16369. +int __lockfunc _mutex_trylock(struct mutex *lock)
  16370. +{
  16371. + int ret = rt_mutex_trylock(&lock->lock);
  16372. +
  16373. + if (ret)
  16374. + mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  16375. +
  16376. + return ret;
  16377. +}
  16378. +EXPORT_SYMBOL(_mutex_trylock);
  16379. +
  16380. +void __lockfunc _mutex_unlock(struct mutex *lock)
  16381. +{
  16382. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  16383. + rt_mutex_unlock(&lock->lock);
  16384. +}
  16385. +EXPORT_SYMBOL(_mutex_unlock);
  16386. +
  16387. +/*
  16388. + * rwlock_t functions
  16389. + */
  16390. +int __lockfunc rt_write_trylock(rwlock_t *rwlock)
  16391. +{
  16392. + int ret;
  16393. +
  16394. + migrate_disable();
  16395. + ret = rt_mutex_trylock(&rwlock->lock);
  16396. + if (ret)
  16397. + rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
  16398. + else
  16399. + migrate_enable();
  16400. +
  16401. + return ret;
  16402. +}
  16403. +EXPORT_SYMBOL(rt_write_trylock);
  16404. +
  16405. +int __lockfunc rt_write_trylock_irqsave(rwlock_t *rwlock, unsigned long *flags)
  16406. +{
  16407. + int ret;
  16408. +
  16409. + *flags = 0;
  16410. + ret = rt_write_trylock(rwlock);
  16411. + return ret;
  16412. +}
  16413. +EXPORT_SYMBOL(rt_write_trylock_irqsave);
  16414. +
  16415. +int __lockfunc rt_read_trylock(rwlock_t *rwlock)
  16416. +{
  16417. + struct rt_mutex *lock = &rwlock->lock;
  16418. + int ret = 1;
  16419. +
  16420. + /*
  16421. + * recursive read locks succeed when current owns the lock,
  16422. + * but not when read_depth == 0 which means that the lock is
  16423. + * write locked.
  16424. + */
  16425. + if (rt_mutex_owner(lock) != current) {
  16426. + migrate_disable();
  16427. + ret = rt_mutex_trylock(lock);
  16428. + if (ret)
  16429. + rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
  16430. + else
  16431. + migrate_enable();
  16432. +
  16433. + } else if (!rwlock->read_depth) {
  16434. + ret = 0;
  16435. + }
  16436. +
  16437. + if (ret)
  16438. + rwlock->read_depth++;
  16439. +
  16440. + return ret;
  16441. +}
  16442. +EXPORT_SYMBOL(rt_read_trylock);
  16443. +
  16444. +void __lockfunc rt_write_lock(rwlock_t *rwlock)
  16445. +{
  16446. + rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_);
  16447. + __rt_spin_lock(&rwlock->lock);
  16448. +}
  16449. +EXPORT_SYMBOL(rt_write_lock);
  16450. +
  16451. +void __lockfunc rt_read_lock(rwlock_t *rwlock)
  16452. +{
  16453. + struct rt_mutex *lock = &rwlock->lock;
  16454. +
  16455. +
  16456. + /*
  16457. + * recursive read locks succeed when current owns the lock
  16458. + */
  16459. + if (rt_mutex_owner(lock) != current) {
  16460. + rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_);
  16461. + __rt_spin_lock(lock);
  16462. + }
  16463. + rwlock->read_depth++;
  16464. +}
  16465. +
  16466. +EXPORT_SYMBOL(rt_read_lock);
  16467. +
  16468. +void __lockfunc rt_write_unlock(rwlock_t *rwlock)
  16469. +{
  16470. + /* NOTE: we always pass in '1' for nested, for simplicity */
  16471. + rwlock_release(&rwlock->dep_map, 1, _RET_IP_);
  16472. + __rt_spin_unlock(&rwlock->lock);
  16473. + migrate_enable();
  16474. +}
  16475. +EXPORT_SYMBOL(rt_write_unlock);
  16476. +
  16477. +void __lockfunc rt_read_unlock(rwlock_t *rwlock)
  16478. +{
  16479. + /* Release the lock only when read_depth is down to 0 */
  16480. + if (--rwlock->read_depth == 0) {
  16481. + rwlock_release(&rwlock->dep_map, 1, _RET_IP_);
  16482. + __rt_spin_unlock(&rwlock->lock);
  16483. + migrate_enable();
  16484. + }
  16485. +}
  16486. +EXPORT_SYMBOL(rt_read_unlock);
  16487. +
  16488. +unsigned long __lockfunc rt_write_lock_irqsave(rwlock_t *rwlock)
  16489. +{
  16490. + rt_write_lock(rwlock);
  16491. +
  16492. + return 0;
  16493. +}
  16494. +EXPORT_SYMBOL(rt_write_lock_irqsave);
  16495. +
  16496. +unsigned long __lockfunc rt_read_lock_irqsave(rwlock_t *rwlock)
  16497. +{
  16498. + rt_read_lock(rwlock);
  16499. +
  16500. + return 0;
  16501. +}
  16502. +EXPORT_SYMBOL(rt_read_lock_irqsave);
  16503. +
  16504. +void __rt_rwlock_init(rwlock_t *rwlock, char *name, struct lock_class_key *key)
  16505. +{
  16506. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  16507. + /*
  16508. + * Make sure we are not reinitializing a held lock:
  16509. + */
  16510. + debug_check_no_locks_freed((void *)rwlock, sizeof(*rwlock));
  16511. + lockdep_init_map(&rwlock->dep_map, name, key, 0);
  16512. +#endif
  16513. + rwlock->lock.save_state = 1;
  16514. + rwlock->read_depth = 0;
  16515. +}
  16516. +EXPORT_SYMBOL(__rt_rwlock_init);
  16517. +
  16518. +/*
  16519. + * rw_semaphores
  16520. + */
  16521. +
  16522. +void rt_up_write(struct rw_semaphore *rwsem)
  16523. +{
  16524. + rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
  16525. + rt_mutex_unlock(&rwsem->lock);
  16526. +}
  16527. +EXPORT_SYMBOL(rt_up_write);
  16528. +
  16529. +void __rt_up_read(struct rw_semaphore *rwsem)
  16530. +{
  16531. + if (--rwsem->read_depth == 0)
  16532. + rt_mutex_unlock(&rwsem->lock);
  16533. +}
  16534. +
  16535. +void rt_up_read(struct rw_semaphore *rwsem)
  16536. +{
  16537. + rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
  16538. + __rt_up_read(rwsem);
  16539. +}
  16540. +EXPORT_SYMBOL(rt_up_read);
  16541. +
  16542. +/*
  16543. + * downgrade a write lock into a read lock
  16544. + * - just wake up any readers at the front of the queue
  16545. + */
  16546. +void rt_downgrade_write(struct rw_semaphore *rwsem)
  16547. +{
  16548. + BUG_ON(rt_mutex_owner(&rwsem->lock) != current);
  16549. + rwsem->read_depth = 1;
  16550. +}
  16551. +EXPORT_SYMBOL(rt_downgrade_write);
  16552. +
  16553. +int rt_down_write_trylock(struct rw_semaphore *rwsem)
  16554. +{
  16555. + int ret = rt_mutex_trylock(&rwsem->lock);
  16556. +
  16557. + if (ret)
  16558. + rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_);
  16559. + return ret;
  16560. +}
  16561. +EXPORT_SYMBOL(rt_down_write_trylock);
  16562. +
  16563. +void rt_down_write(struct rw_semaphore *rwsem)
  16564. +{
  16565. + rwsem_acquire(&rwsem->dep_map, 0, 0, _RET_IP_);
  16566. + rt_mutex_lock(&rwsem->lock);
  16567. +}
  16568. +EXPORT_SYMBOL(rt_down_write);
  16569. +
  16570. +void rt_down_write_nested(struct rw_semaphore *rwsem, int subclass)
  16571. +{
  16572. + rwsem_acquire(&rwsem->dep_map, subclass, 0, _RET_IP_);
  16573. + rt_mutex_lock(&rwsem->lock);
  16574. +}
  16575. +EXPORT_SYMBOL(rt_down_write_nested);
  16576. +
  16577. +void rt_down_write_nested_lock(struct rw_semaphore *rwsem,
  16578. + struct lockdep_map *nest)
  16579. +{
  16580. + rwsem_acquire_nest(&rwsem->dep_map, 0, 0, nest, _RET_IP_);
  16581. + rt_mutex_lock(&rwsem->lock);
  16582. +}
  16583. +EXPORT_SYMBOL(rt_down_write_nested_lock);
  16584. +
  16585. +int rt__down_read_trylock(struct rw_semaphore *rwsem)
  16586. +{
  16587. + struct rt_mutex *lock = &rwsem->lock;
  16588. + int ret = 1;
  16589. +
  16590. + /*
  16591. + * recursive read locks succeed when current owns the rwsem,
  16592. + * but not when read_depth == 0 which means that the rwsem is
  16593. + * write locked.
  16594. + */
  16595. + if (rt_mutex_owner(lock) != current)
  16596. + ret = rt_mutex_trylock(&rwsem->lock);
  16597. + else if (!rwsem->read_depth)
  16598. + ret = 0;
  16599. +
  16600. + if (ret)
  16601. + rwsem->read_depth++;
  16602. + return ret;
  16603. +
  16604. +}
  16605. +
  16606. +int rt_down_read_trylock(struct rw_semaphore *rwsem)
  16607. +{
  16608. + int ret;
  16609. +
  16610. + ret = rt__down_read_trylock(rwsem);
  16611. + if (ret)
  16612. + rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_);
  16613. +
  16614. + return ret;
  16615. +}
  16616. +EXPORT_SYMBOL(rt_down_read_trylock);
  16617. +
  16618. +void rt__down_read(struct rw_semaphore *rwsem)
  16619. +{
  16620. + struct rt_mutex *lock = &rwsem->lock;
  16621. +
  16622. + if (rt_mutex_owner(lock) != current)
  16623. + rt_mutex_lock(&rwsem->lock);
  16624. + rwsem->read_depth++;
  16625. +}
  16626. +EXPORT_SYMBOL(rt__down_read);
  16627. +
  16628. +static void __rt_down_read(struct rw_semaphore *rwsem, int subclass)
  16629. +{
  16630. + rwsem_acquire_read(&rwsem->dep_map, subclass, 0, _RET_IP_);
  16631. + rt__down_read(rwsem);
  16632. +}
  16633. +
  16634. +void rt_down_read(struct rw_semaphore *rwsem)
  16635. +{
  16636. + __rt_down_read(rwsem, 0);
  16637. +}
  16638. +EXPORT_SYMBOL(rt_down_read);
  16639. +
  16640. +void rt_down_read_nested(struct rw_semaphore *rwsem, int subclass)
  16641. +{
  16642. + __rt_down_read(rwsem, subclass);
  16643. +}
  16644. +EXPORT_SYMBOL(rt_down_read_nested);
  16645. +
  16646. +void __rt_rwsem_init(struct rw_semaphore *rwsem, const char *name,
  16647. + struct lock_class_key *key)
  16648. +{
  16649. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  16650. + /*
  16651. + * Make sure we are not reinitializing a held lock:
  16652. + */
  16653. + debug_check_no_locks_freed((void *)rwsem, sizeof(*rwsem));
  16654. + lockdep_init_map(&rwsem->dep_map, name, key, 0);
  16655. +#endif
  16656. + rwsem->read_depth = 0;
  16657. + rwsem->lock.save_state = 0;
  16658. +}
  16659. +EXPORT_SYMBOL(__rt_rwsem_init);
  16660. +
  16661. +/**
  16662. + * atomic_dec_and_mutex_lock - return holding mutex if we dec to 0
  16663. + * @cnt: the atomic which we are to dec
  16664. + * @lock: the mutex to return holding if we dec to 0
  16665. + *
  16666. + * return true and hold lock if we dec to 0, return false otherwise
  16667. + */
  16668. +int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock)
  16669. +{
  16670. + /* dec if we can't possibly hit 0 */
  16671. + if (atomic_add_unless(cnt, -1, 1))
  16672. + return 0;
  16673. + /* we might hit 0, so take the lock */
  16674. + mutex_lock(lock);
  16675. + if (!atomic_dec_and_test(cnt)) {
  16676. + /* when we actually did the dec, we didn't hit 0 */
  16677. + mutex_unlock(lock);
  16678. + return 0;
  16679. + }
  16680. + /* we hit 0, and we hold the lock */
  16681. + return 1;
  16682. +}
  16683. +EXPORT_SYMBOL(atomic_dec_and_mutex_lock);
  16684. diff -Nur linux-4.4.13.orig/kernel/locking/rtmutex.c linux-4.4.13/kernel/locking/rtmutex.c
  16685. --- linux-4.4.13.orig/kernel/locking/rtmutex.c 2016-06-08 03:14:51.000000000 +0200
  16686. +++ linux-4.4.13/kernel/locking/rtmutex.c 2016-06-22 21:55:08.050523867 +0200
  16687. @@ -7,6 +7,11 @@
  16688. * Copyright (C) 2005-2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  16689. * Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt
  16690. * Copyright (C) 2006 Esben Nielsen
  16691. + * Adaptive Spinlocks:
  16692. + * Copyright (C) 2008 Novell, Inc., Gregory Haskins, Sven Dietrich,
  16693. + * and Peter Morreale,
  16694. + * Adaptive Spinlocks simplification:
  16695. + * Copyright (C) 2008 Red Hat, Inc., Steven Rostedt <srostedt@redhat.com>
  16696. *
  16697. * See Documentation/locking/rt-mutex-design.txt for details.
  16698. */
  16699. @@ -16,6 +21,7 @@
  16700. #include <linux/sched/rt.h>
  16701. #include <linux/sched/deadline.h>
  16702. #include <linux/timer.h>
  16703. +#include <linux/ww_mutex.h>
  16704. #include "rtmutex_common.h"
  16705. @@ -69,6 +75,12 @@
  16706. clear_rt_mutex_waiters(lock);
  16707. }
  16708. +static int rt_mutex_real_waiter(struct rt_mutex_waiter *waiter)
  16709. +{
  16710. + return waiter && waiter != PI_WAKEUP_INPROGRESS &&
  16711. + waiter != PI_REQUEUE_INPROGRESS;
  16712. +}
  16713. +
  16714. /*
  16715. * We can speed up the acquire/release, if there's no debugging state to be
  16716. * set up.
  16717. @@ -99,13 +111,14 @@
  16718. * 2) Drop lock->wait_lock
  16719. * 3) Try to unlock the lock with cmpxchg
  16720. */
  16721. -static inline bool unlock_rt_mutex_safe(struct rt_mutex *lock)
  16722. +static inline bool unlock_rt_mutex_safe(struct rt_mutex *lock,
  16723. + unsigned long flags)
  16724. __releases(lock->wait_lock)
  16725. {
  16726. struct task_struct *owner = rt_mutex_owner(lock);
  16727. clear_rt_mutex_waiters(lock);
  16728. - raw_spin_unlock(&lock->wait_lock);
  16729. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  16730. /*
  16731. * If a new waiter comes in between the unlock and the cmpxchg
  16732. * we have two situations:
  16733. @@ -147,11 +160,12 @@
  16734. /*
  16735. * Simple slow path only version: lock->owner is protected by lock->wait_lock.
  16736. */
  16737. -static inline bool unlock_rt_mutex_safe(struct rt_mutex *lock)
  16738. +static inline bool unlock_rt_mutex_safe(struct rt_mutex *lock,
  16739. + unsigned long flags)
  16740. __releases(lock->wait_lock)
  16741. {
  16742. lock->owner = NULL;
  16743. - raw_spin_unlock(&lock->wait_lock);
  16744. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  16745. return true;
  16746. }
  16747. #endif
  16748. @@ -348,6 +362,14 @@
  16749. return debug_rt_mutex_detect_deadlock(waiter, chwalk);
  16750. }
  16751. +static void rt_mutex_wake_waiter(struct rt_mutex_waiter *waiter)
  16752. +{
  16753. + if (waiter->savestate)
  16754. + wake_up_lock_sleeper(waiter->task);
  16755. + else
  16756. + wake_up_process(waiter->task);
  16757. +}
  16758. +
  16759. /*
  16760. * Max number of times we'll walk the boosting chain:
  16761. */
  16762. @@ -355,7 +377,8 @@
  16763. static inline struct rt_mutex *task_blocked_on_lock(struct task_struct *p)
  16764. {
  16765. - return p->pi_blocked_on ? p->pi_blocked_on->lock : NULL;
  16766. + return rt_mutex_real_waiter(p->pi_blocked_on) ?
  16767. + p->pi_blocked_on->lock : NULL;
  16768. }
  16769. /*
  16770. @@ -433,7 +456,6 @@
  16771. int ret = 0, depth = 0;
  16772. struct rt_mutex *lock;
  16773. bool detect_deadlock;
  16774. - unsigned long flags;
  16775. bool requeue = true;
  16776. detect_deadlock = rt_mutex_cond_detect_deadlock(orig_waiter, chwalk);
  16777. @@ -476,7 +498,7 @@
  16778. /*
  16779. * [1] Task cannot go away as we did a get_task() before !
  16780. */
  16781. - raw_spin_lock_irqsave(&task->pi_lock, flags);
  16782. + raw_spin_lock_irq(&task->pi_lock);
  16783. /*
  16784. * [2] Get the waiter on which @task is blocked on.
  16785. @@ -492,7 +514,7 @@
  16786. * reached or the state of the chain has changed while we
  16787. * dropped the locks.
  16788. */
  16789. - if (!waiter)
  16790. + if (!rt_mutex_real_waiter(waiter))
  16791. goto out_unlock_pi;
  16792. /*
  16793. @@ -560,7 +582,7 @@
  16794. * operations.
  16795. */
  16796. if (!raw_spin_trylock(&lock->wait_lock)) {
  16797. - raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  16798. + raw_spin_unlock_irq(&task->pi_lock);
  16799. cpu_relax();
  16800. goto retry;
  16801. }
  16802. @@ -591,7 +613,7 @@
  16803. /*
  16804. * No requeue[7] here. Just release @task [8]
  16805. */
  16806. - raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  16807. + raw_spin_unlock(&task->pi_lock);
  16808. put_task_struct(task);
  16809. /*
  16810. @@ -599,14 +621,14 @@
  16811. * If there is no owner of the lock, end of chain.
  16812. */
  16813. if (!rt_mutex_owner(lock)) {
  16814. - raw_spin_unlock(&lock->wait_lock);
  16815. + raw_spin_unlock_irq(&lock->wait_lock);
  16816. return 0;
  16817. }
  16818. /* [10] Grab the next task, i.e. owner of @lock */
  16819. task = rt_mutex_owner(lock);
  16820. get_task_struct(task);
  16821. - raw_spin_lock_irqsave(&task->pi_lock, flags);
  16822. + raw_spin_lock(&task->pi_lock);
  16823. /*
  16824. * No requeue [11] here. We just do deadlock detection.
  16825. @@ -621,8 +643,8 @@
  16826. top_waiter = rt_mutex_top_waiter(lock);
  16827. /* [13] Drop locks */
  16828. - raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  16829. - raw_spin_unlock(&lock->wait_lock);
  16830. + raw_spin_unlock(&task->pi_lock);
  16831. + raw_spin_unlock_irq(&lock->wait_lock);
  16832. /* If owner is not blocked, end of chain. */
  16833. if (!next_lock)
  16834. @@ -643,7 +665,7 @@
  16835. rt_mutex_enqueue(lock, waiter);
  16836. /* [8] Release the task */
  16837. - raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  16838. + raw_spin_unlock(&task->pi_lock);
  16839. put_task_struct(task);
  16840. /*
  16841. @@ -654,21 +676,24 @@
  16842. * follow here. This is the end of the chain we are walking.
  16843. */
  16844. if (!rt_mutex_owner(lock)) {
  16845. + struct rt_mutex_waiter *lock_top_waiter;
  16846. +
  16847. /*
  16848. * If the requeue [7] above changed the top waiter,
  16849. * then we need to wake the new top waiter up to try
  16850. * to get the lock.
  16851. */
  16852. - if (prerequeue_top_waiter != rt_mutex_top_waiter(lock))
  16853. - wake_up_process(rt_mutex_top_waiter(lock)->task);
  16854. - raw_spin_unlock(&lock->wait_lock);
  16855. + lock_top_waiter = rt_mutex_top_waiter(lock);
  16856. + if (prerequeue_top_waiter != lock_top_waiter)
  16857. + rt_mutex_wake_waiter(lock_top_waiter);
  16858. + raw_spin_unlock_irq(&lock->wait_lock);
  16859. return 0;
  16860. }
  16861. /* [10] Grab the next task, i.e. the owner of @lock */
  16862. task = rt_mutex_owner(lock);
  16863. get_task_struct(task);
  16864. - raw_spin_lock_irqsave(&task->pi_lock, flags);
  16865. + raw_spin_lock(&task->pi_lock);
  16866. /* [11] requeue the pi waiters if necessary */
  16867. if (waiter == rt_mutex_top_waiter(lock)) {
  16868. @@ -722,8 +747,8 @@
  16869. top_waiter = rt_mutex_top_waiter(lock);
  16870. /* [13] Drop the locks */
  16871. - raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  16872. - raw_spin_unlock(&lock->wait_lock);
  16873. + raw_spin_unlock(&task->pi_lock);
  16874. + raw_spin_unlock_irq(&lock->wait_lock);
  16875. /*
  16876. * Make the actual exit decisions [12], based on the stored
  16877. @@ -746,28 +771,46 @@
  16878. goto again;
  16879. out_unlock_pi:
  16880. - raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  16881. + raw_spin_unlock_irq(&task->pi_lock);
  16882. out_put_task:
  16883. put_task_struct(task);
  16884. return ret;
  16885. }
  16886. +
  16887. +#define STEAL_NORMAL 0
  16888. +#define STEAL_LATERAL 1
  16889. +
  16890. +/*
  16891. + * Note that RT tasks are excluded from lateral-steals to prevent the
  16892. + * introduction of an unbounded latency
  16893. + */
  16894. +static inline int lock_is_stealable(struct task_struct *task,
  16895. + struct task_struct *pendowner, int mode)
  16896. +{
  16897. + if (mode == STEAL_NORMAL || rt_task(task)) {
  16898. + if (task->prio >= pendowner->prio)
  16899. + return 0;
  16900. + } else if (task->prio > pendowner->prio)
  16901. + return 0;
  16902. + return 1;
  16903. +}
  16904. +
  16905. /*
  16906. * Try to take an rt-mutex
  16907. *
  16908. - * Must be called with lock->wait_lock held.
  16909. + * Must be called with lock->wait_lock held and interrupts disabled
  16910. *
  16911. * @lock: The lock to be acquired.
  16912. * @task: The task which wants to acquire the lock
  16913. * @waiter: The waiter that is queued to the lock's wait tree if the
  16914. * callsite called task_blocked_on_lock(), otherwise NULL
  16915. */
  16916. -static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
  16917. - struct rt_mutex_waiter *waiter)
  16918. +static int __try_to_take_rt_mutex(struct rt_mutex *lock,
  16919. + struct task_struct *task,
  16920. + struct rt_mutex_waiter *waiter, int mode)
  16921. {
  16922. - unsigned long flags;
  16923. -
  16924. /*
  16925. * Before testing whether we can acquire @lock, we set the
  16926. * RT_MUTEX_HAS_WAITERS bit in @lock->owner. This forces all
  16927. @@ -803,8 +846,10 @@
  16928. * If waiter is not the highest priority waiter of
  16929. * @lock, give up.
  16930. */
  16931. - if (waiter != rt_mutex_top_waiter(lock))
  16932. + if (waiter != rt_mutex_top_waiter(lock)) {
  16933. + /* XXX lock_is_stealable() ? */
  16934. return 0;
  16935. + }
  16936. /*
  16937. * We can acquire the lock. Remove the waiter from the
  16938. @@ -822,14 +867,10 @@
  16939. * not need to be dequeued.
  16940. */
  16941. if (rt_mutex_has_waiters(lock)) {
  16942. - /*
  16943. - * If @task->prio is greater than or equal to
  16944. - * the top waiter priority (kernel view),
  16945. - * @task lost.
  16946. - */
  16947. - if (task->prio >= rt_mutex_top_waiter(lock)->prio)
  16948. - return 0;
  16949. + struct task_struct *pown = rt_mutex_top_waiter(lock)->task;
  16950. + if (task != pown && !lock_is_stealable(task, pown, mode))
  16951. + return 0;
  16952. /*
  16953. * The current top waiter stays enqueued. We
  16954. * don't have to change anything in the lock
  16955. @@ -852,7 +893,7 @@
  16956. * case, but conditionals are more expensive than a redundant
  16957. * store.
  16958. */
  16959. - raw_spin_lock_irqsave(&task->pi_lock, flags);
  16960. + raw_spin_lock(&task->pi_lock);
  16961. task->pi_blocked_on = NULL;
  16962. /*
  16963. * Finish the lock acquisition. @task is the new owner. If
  16964. @@ -861,7 +902,7 @@
  16965. */
  16966. if (rt_mutex_has_waiters(lock))
  16967. rt_mutex_enqueue_pi(task, rt_mutex_top_waiter(lock));
  16968. - raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  16969. + raw_spin_unlock(&task->pi_lock);
  16970. takeit:
  16971. /* We got the lock. */
  16972. @@ -878,12 +919,405 @@
  16973. return 1;
  16974. }
  16975. +#ifdef CONFIG_PREEMPT_RT_FULL
  16976. +/*
  16977. + * preemptible spin_lock functions:
  16978. + */
  16979. +static inline void rt_spin_lock_fastlock(struct rt_mutex *lock,
  16980. + void (*slowfn)(struct rt_mutex *lock,
  16981. + bool mg_off),
  16982. + bool do_mig_dis)
  16983. +{
  16984. + might_sleep_no_state_check();
  16985. +
  16986. + if (do_mig_dis)
  16987. + migrate_disable();
  16988. +
  16989. + if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current)))
  16990. + rt_mutex_deadlock_account_lock(lock, current);
  16991. + else
  16992. + slowfn(lock, do_mig_dis);
  16993. +}
  16994. +
  16995. +static inline void rt_spin_lock_fastunlock(struct rt_mutex *lock,
  16996. + void (*slowfn)(struct rt_mutex *lock))
  16997. +{
  16998. + if (likely(rt_mutex_cmpxchg_release(lock, current, NULL)))
  16999. + rt_mutex_deadlock_account_unlock(current);
  17000. + else
  17001. + slowfn(lock);
  17002. +}
  17003. +#ifdef CONFIG_SMP
  17004. +/*
  17005. + * Note that owner is a speculative pointer and dereferencing relies
  17006. + * on rcu_read_lock() and the check against the lock owner.
  17007. + */
  17008. +static int adaptive_wait(struct rt_mutex *lock,
  17009. + struct task_struct *owner)
  17010. +{
  17011. + int res = 0;
  17012. +
  17013. + rcu_read_lock();
  17014. + for (;;) {
  17015. + if (owner != rt_mutex_owner(lock))
  17016. + break;
  17017. + /*
  17018. + * Ensure that owner->on_cpu is dereferenced _after_
  17019. + * checking the above to be valid.
  17020. + */
  17021. + barrier();
  17022. + if (!owner->on_cpu) {
  17023. + res = 1;
  17024. + break;
  17025. + }
  17026. + cpu_relax();
  17027. + }
  17028. + rcu_read_unlock();
  17029. + return res;
  17030. +}
  17031. +#else
  17032. +static int adaptive_wait(struct rt_mutex *lock,
  17033. + struct task_struct *orig_owner)
  17034. +{
  17035. + return 1;
  17036. +}
  17037. +#endif
  17038. +
  17039. +static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
  17040. + struct rt_mutex_waiter *waiter,
  17041. + struct task_struct *task,
  17042. + enum rtmutex_chainwalk chwalk);
  17043. +/*
  17044. + * Slow path lock function spin_lock style: this variant is very
  17045. + * careful not to miss any non-lock wakeups.
  17046. + *
  17047. + * We store the current state under p->pi_lock in p->saved_state and
  17048. + * the try_to_wake_up() code handles this accordingly.
  17049. + */
  17050. +static void noinline __sched rt_spin_lock_slowlock(struct rt_mutex *lock,
  17051. + bool mg_off)
  17052. +{
  17053. + struct task_struct *lock_owner, *self = current;
  17054. + struct rt_mutex_waiter waiter, *top_waiter;
  17055. + unsigned long flags;
  17056. + int ret;
  17057. +
  17058. + rt_mutex_init_waiter(&waiter, true);
  17059. +
  17060. + raw_spin_lock_irqsave(&lock->wait_lock, flags);
  17061. +
  17062. + if (__try_to_take_rt_mutex(lock, self, NULL, STEAL_LATERAL)) {
  17063. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  17064. + return;
  17065. + }
  17066. +
  17067. + BUG_ON(rt_mutex_owner(lock) == self);
  17068. +
  17069. + /*
  17070. + * We save whatever state the task is in and we'll restore it
  17071. + * after acquiring the lock taking real wakeups into account
  17072. + * as well. We are serialized via pi_lock against wakeups. See
  17073. + * try_to_wake_up().
  17074. + */
  17075. + raw_spin_lock(&self->pi_lock);
  17076. + self->saved_state = self->state;
  17077. + __set_current_state_no_track(TASK_UNINTERRUPTIBLE);
  17078. + raw_spin_unlock(&self->pi_lock);
  17079. +
  17080. + ret = task_blocks_on_rt_mutex(lock, &waiter, self, RT_MUTEX_MIN_CHAINWALK);
  17081. + BUG_ON(ret);
  17082. +
  17083. + for (;;) {
  17084. + /* Try to acquire the lock again. */
  17085. + if (__try_to_take_rt_mutex(lock, self, &waiter, STEAL_LATERAL))
  17086. + break;
  17087. +
  17088. + top_waiter = rt_mutex_top_waiter(lock);
  17089. + lock_owner = rt_mutex_owner(lock);
  17090. +
  17091. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  17092. +
  17093. + debug_rt_mutex_print_deadlock(&waiter);
  17094. +
  17095. + if (top_waiter != &waiter || adaptive_wait(lock, lock_owner)) {
  17096. + if (mg_off)
  17097. + migrate_enable();
  17098. + schedule();
  17099. + if (mg_off)
  17100. + migrate_disable();
  17101. + }
  17102. +
  17103. + raw_spin_lock_irqsave(&lock->wait_lock, flags);
  17104. +
  17105. + raw_spin_lock(&self->pi_lock);
  17106. + __set_current_state_no_track(TASK_UNINTERRUPTIBLE);
  17107. + raw_spin_unlock(&self->pi_lock);
  17108. + }
  17109. +
  17110. + /*
  17111. + * Restore the task state to current->saved_state. We set it
  17112. + * to the original state above and the try_to_wake_up() code
  17113. + * has possibly updated it when a real (non-rtmutex) wakeup
  17114. + * happened while we were blocked. Clear saved_state so
  17115. + * try_to_wakeup() does not get confused.
  17116. + */
  17117. + raw_spin_lock(&self->pi_lock);
  17118. + __set_current_state_no_track(self->saved_state);
  17119. + self->saved_state = TASK_RUNNING;
  17120. + raw_spin_unlock(&self->pi_lock);
  17121. +
  17122. + /*
  17123. + * try_to_take_rt_mutex() sets the waiter bit
  17124. + * unconditionally. We might have to fix that up:
  17125. + */
  17126. + fixup_rt_mutex_waiters(lock);
  17127. +
  17128. + BUG_ON(rt_mutex_has_waiters(lock) && &waiter == rt_mutex_top_waiter(lock));
  17129. + BUG_ON(!RB_EMPTY_NODE(&waiter.tree_entry));
  17130. +
  17131. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  17132. +
  17133. + debug_rt_mutex_free_waiter(&waiter);
  17134. +}
  17135. +
  17136. +static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
  17137. + struct wake_q_head *wake_sleeper_q,
  17138. + struct rt_mutex *lock);
  17139. +/*
  17140. + * Slow path to release a rt_mutex spin_lock style
  17141. + */
  17142. +static void noinline __sched rt_spin_lock_slowunlock(struct rt_mutex *lock)
  17143. +{
  17144. + unsigned long flags;
  17145. + WAKE_Q(wake_q);
  17146. + WAKE_Q(wake_sleeper_q);
  17147. +
  17148. + raw_spin_lock_irqsave(&lock->wait_lock, flags);
  17149. +
  17150. + debug_rt_mutex_unlock(lock);
  17151. +
  17152. + rt_mutex_deadlock_account_unlock(current);
  17153. +
  17154. + if (!rt_mutex_has_waiters(lock)) {
  17155. + lock->owner = NULL;
  17156. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  17157. + return;
  17158. + }
  17159. +
  17160. + mark_wakeup_next_waiter(&wake_q, &wake_sleeper_q, lock);
  17161. +
  17162. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  17163. + wake_up_q(&wake_q);
  17164. + wake_up_q_sleeper(&wake_sleeper_q);
  17165. +
  17166. + /* Undo pi boosting.when necessary */
  17167. + rt_mutex_adjust_prio(current);
  17168. +}
  17169. +
  17170. +void __lockfunc rt_spin_lock__no_mg(spinlock_t *lock)
  17171. +{
  17172. + rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock, false);
  17173. + spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  17174. +}
  17175. +EXPORT_SYMBOL(rt_spin_lock__no_mg);
  17176. +
  17177. +void __lockfunc rt_spin_lock(spinlock_t *lock)
  17178. +{
  17179. + rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock, true);
  17180. + spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  17181. +}
  17182. +EXPORT_SYMBOL(rt_spin_lock);
  17183. +
  17184. +void __lockfunc __rt_spin_lock(struct rt_mutex *lock)
  17185. +{
  17186. + rt_spin_lock_fastlock(lock, rt_spin_lock_slowlock, true);
  17187. +}
  17188. +EXPORT_SYMBOL(__rt_spin_lock);
  17189. +
  17190. +void __lockfunc __rt_spin_lock__no_mg(struct rt_mutex *lock)
  17191. +{
  17192. + rt_spin_lock_fastlock(lock, rt_spin_lock_slowlock, false);
  17193. +}
  17194. +EXPORT_SYMBOL(__rt_spin_lock__no_mg);
  17195. +
  17196. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  17197. +void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass)
  17198. +{
  17199. + spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
  17200. + rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock, true);
  17201. +}
  17202. +EXPORT_SYMBOL(rt_spin_lock_nested);
  17203. +#endif
  17204. +
  17205. +void __lockfunc rt_spin_unlock__no_mg(spinlock_t *lock)
  17206. +{
  17207. + /* NOTE: we always pass in '1' for nested, for simplicity */
  17208. + spin_release(&lock->dep_map, 1, _RET_IP_);
  17209. + rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock);
  17210. +}
  17211. +EXPORT_SYMBOL(rt_spin_unlock__no_mg);
  17212. +
  17213. +void __lockfunc rt_spin_unlock(spinlock_t *lock)
  17214. +{
  17215. + /* NOTE: we always pass in '1' for nested, for simplicity */
  17216. + spin_release(&lock->dep_map, 1, _RET_IP_);
  17217. + rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock);
  17218. + migrate_enable();
  17219. +}
  17220. +EXPORT_SYMBOL(rt_spin_unlock);
  17221. +
  17222. +void __lockfunc __rt_spin_unlock(struct rt_mutex *lock)
  17223. +{
  17224. + rt_spin_lock_fastunlock(lock, rt_spin_lock_slowunlock);
  17225. +}
  17226. +EXPORT_SYMBOL(__rt_spin_unlock);
  17227. +
  17228. +/*
  17229. + * Wait for the lock to get unlocked: instead of polling for an unlock
  17230. + * (like raw spinlocks do), we lock and unlock, to force the kernel to
  17231. + * schedule if there's contention:
  17232. + */
  17233. +void __lockfunc rt_spin_unlock_wait(spinlock_t *lock)
  17234. +{
  17235. + spin_lock(lock);
  17236. + spin_unlock(lock);
  17237. +}
  17238. +EXPORT_SYMBOL(rt_spin_unlock_wait);
  17239. +
  17240. +int __lockfunc __rt_spin_trylock(struct rt_mutex *lock)
  17241. +{
  17242. + return rt_mutex_trylock(lock);
  17243. +}
  17244. +
  17245. +int __lockfunc rt_spin_trylock__no_mg(spinlock_t *lock)
  17246. +{
  17247. + int ret;
  17248. +
  17249. + ret = rt_mutex_trylock(&lock->lock);
  17250. + if (ret)
  17251. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  17252. + return ret;
  17253. +}
  17254. +EXPORT_SYMBOL(rt_spin_trylock__no_mg);
  17255. +
  17256. +int __lockfunc rt_spin_trylock(spinlock_t *lock)
  17257. +{
  17258. + int ret;
  17259. +
  17260. + migrate_disable();
  17261. + ret = rt_mutex_trylock(&lock->lock);
  17262. + if (ret)
  17263. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  17264. + else
  17265. + migrate_enable();
  17266. + return ret;
  17267. +}
  17268. +EXPORT_SYMBOL(rt_spin_trylock);
  17269. +
  17270. +int __lockfunc rt_spin_trylock_bh(spinlock_t *lock)
  17271. +{
  17272. + int ret;
  17273. +
  17274. + local_bh_disable();
  17275. + ret = rt_mutex_trylock(&lock->lock);
  17276. + if (ret) {
  17277. + migrate_disable();
  17278. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  17279. + } else
  17280. + local_bh_enable();
  17281. + return ret;
  17282. +}
  17283. +EXPORT_SYMBOL(rt_spin_trylock_bh);
  17284. +
  17285. +int __lockfunc rt_spin_trylock_irqsave(spinlock_t *lock, unsigned long *flags)
  17286. +{
  17287. + int ret;
  17288. +
  17289. + *flags = 0;
  17290. + ret = rt_mutex_trylock(&lock->lock);
  17291. + if (ret) {
  17292. + migrate_disable();
  17293. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  17294. + }
  17295. + return ret;
  17296. +}
  17297. +EXPORT_SYMBOL(rt_spin_trylock_irqsave);
  17298. +
  17299. +int atomic_dec_and_spin_lock(atomic_t *atomic, spinlock_t *lock)
  17300. +{
  17301. + /* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */
  17302. + if (atomic_add_unless(atomic, -1, 1))
  17303. + return 0;
  17304. + rt_spin_lock(lock);
  17305. + if (atomic_dec_and_test(atomic))
  17306. + return 1;
  17307. + rt_spin_unlock(lock);
  17308. + return 0;
  17309. +}
  17310. +EXPORT_SYMBOL(atomic_dec_and_spin_lock);
  17311. +
  17312. + void
  17313. +__rt_spin_lock_init(spinlock_t *lock, char *name, struct lock_class_key *key)
  17314. +{
  17315. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  17316. + /*
  17317. + * Make sure we are not reinitializing a held lock:
  17318. + */
  17319. + debug_check_no_locks_freed((void *)lock, sizeof(*lock));
  17320. + lockdep_init_map(&lock->dep_map, name, key, 0);
  17321. +#endif
  17322. +}
  17323. +EXPORT_SYMBOL(__rt_spin_lock_init);
  17324. +
  17325. +#endif /* PREEMPT_RT_FULL */
  17326. +
  17327. +#ifdef CONFIG_PREEMPT_RT_FULL
  17328. + static inline int __sched
  17329. +__mutex_lock_check_stamp(struct rt_mutex *lock, struct ww_acquire_ctx *ctx)
  17330. +{
  17331. + struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock);
  17332. + struct ww_acquire_ctx *hold_ctx = ACCESS_ONCE(ww->ctx);
  17333. +
  17334. + if (!hold_ctx)
  17335. + return 0;
  17336. +
  17337. + if (unlikely(ctx == hold_ctx))
  17338. + return -EALREADY;
  17339. +
  17340. + if (ctx->stamp - hold_ctx->stamp <= LONG_MAX &&
  17341. + (ctx->stamp != hold_ctx->stamp || ctx > hold_ctx)) {
  17342. +#ifdef CONFIG_DEBUG_MUTEXES
  17343. + DEBUG_LOCKS_WARN_ON(ctx->contending_lock);
  17344. + ctx->contending_lock = ww;
  17345. +#endif
  17346. + return -EDEADLK;
  17347. + }
  17348. +
  17349. + return 0;
  17350. +}
  17351. +#else
  17352. + static inline int __sched
  17353. +__mutex_lock_check_stamp(struct rt_mutex *lock, struct ww_acquire_ctx *ctx)
  17354. +{
  17355. + BUG();
  17356. + return 0;
  17357. +}
  17358. +
  17359. +#endif
  17360. +
  17361. +static inline int
  17362. +try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
  17363. + struct rt_mutex_waiter *waiter)
  17364. +{
  17365. + return __try_to_take_rt_mutex(lock, task, waiter, STEAL_NORMAL);
  17366. +}
  17367. +
  17368. /*
  17369. * Task blocks on lock.
  17370. *
  17371. * Prepare waiter and propagate pi chain
  17372. *
  17373. - * This must be called with lock->wait_lock held.
  17374. + * This must be called with lock->wait_lock held and interrupts disabled
  17375. */
  17376. static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
  17377. struct rt_mutex_waiter *waiter,
  17378. @@ -894,7 +1328,6 @@
  17379. struct rt_mutex_waiter *top_waiter = waiter;
  17380. struct rt_mutex *next_lock;
  17381. int chain_walk = 0, res;
  17382. - unsigned long flags;
  17383. /*
  17384. * Early deadlock detection. We really don't want the task to
  17385. @@ -908,7 +1341,24 @@
  17386. if (owner == task)
  17387. return -EDEADLK;
  17388. - raw_spin_lock_irqsave(&task->pi_lock, flags);
  17389. + raw_spin_lock(&task->pi_lock);
  17390. +
  17391. + /*
  17392. + * In the case of futex requeue PI, this will be a proxy
  17393. + * lock. The task will wake unaware that it is enqueueed on
  17394. + * this lock. Avoid blocking on two locks and corrupting
  17395. + * pi_blocked_on via the PI_WAKEUP_INPROGRESS
  17396. + * flag. futex_wait_requeue_pi() sets this when it wakes up
  17397. + * before requeue (due to a signal or timeout). Do not enqueue
  17398. + * the task if PI_WAKEUP_INPROGRESS is set.
  17399. + */
  17400. + if (task != current && task->pi_blocked_on == PI_WAKEUP_INPROGRESS) {
  17401. + raw_spin_unlock(&task->pi_lock);
  17402. + return -EAGAIN;
  17403. + }
  17404. +
  17405. + BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on));
  17406. +
  17407. __rt_mutex_adjust_prio(task);
  17408. waiter->task = task;
  17409. waiter->lock = lock;
  17410. @@ -921,18 +1371,18 @@
  17411. task->pi_blocked_on = waiter;
  17412. - raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  17413. + raw_spin_unlock(&task->pi_lock);
  17414. if (!owner)
  17415. return 0;
  17416. - raw_spin_lock_irqsave(&owner->pi_lock, flags);
  17417. + raw_spin_lock(&owner->pi_lock);
  17418. if (waiter == rt_mutex_top_waiter(lock)) {
  17419. rt_mutex_dequeue_pi(owner, top_waiter);
  17420. rt_mutex_enqueue_pi(owner, waiter);
  17421. __rt_mutex_adjust_prio(owner);
  17422. - if (owner->pi_blocked_on)
  17423. + if (rt_mutex_real_waiter(owner->pi_blocked_on))
  17424. chain_walk = 1;
  17425. } else if (rt_mutex_cond_detect_deadlock(waiter, chwalk)) {
  17426. chain_walk = 1;
  17427. @@ -941,7 +1391,7 @@
  17428. /* Store the lock on which owner is blocked or NULL */
  17429. next_lock = task_blocked_on_lock(owner);
  17430. - raw_spin_unlock_irqrestore(&owner->pi_lock, flags);
  17431. + raw_spin_unlock(&owner->pi_lock);
  17432. /*
  17433. * Even if full deadlock detection is on, if the owner is not
  17434. * blocked itself, we can avoid finding this out in the chain
  17435. @@ -957,12 +1407,12 @@
  17436. */
  17437. get_task_struct(owner);
  17438. - raw_spin_unlock(&lock->wait_lock);
  17439. + raw_spin_unlock_irq(&lock->wait_lock);
  17440. res = rt_mutex_adjust_prio_chain(owner, chwalk, lock,
  17441. next_lock, waiter, task);
  17442. - raw_spin_lock(&lock->wait_lock);
  17443. + raw_spin_lock_irq(&lock->wait_lock);
  17444. return res;
  17445. }
  17446. @@ -971,15 +1421,15 @@
  17447. * Remove the top waiter from the current tasks pi waiter tree and
  17448. * queue it up.
  17449. *
  17450. - * Called with lock->wait_lock held.
  17451. + * Called with lock->wait_lock held and interrupts disabled.
  17452. */
  17453. static void mark_wakeup_next_waiter(struct wake_q_head *wake_q,
  17454. + struct wake_q_head *wake_sleeper_q,
  17455. struct rt_mutex *lock)
  17456. {
  17457. struct rt_mutex_waiter *waiter;
  17458. - unsigned long flags;
  17459. - raw_spin_lock_irqsave(&current->pi_lock, flags);
  17460. + raw_spin_lock(&current->pi_lock);
  17461. waiter = rt_mutex_top_waiter(lock);
  17462. @@ -1001,15 +1451,18 @@
  17463. */
  17464. lock->owner = (void *) RT_MUTEX_HAS_WAITERS;
  17465. - raw_spin_unlock_irqrestore(&current->pi_lock, flags);
  17466. + raw_spin_unlock(&current->pi_lock);
  17467. - wake_q_add(wake_q, waiter->task);
  17468. + if (waiter->savestate)
  17469. + wake_q_add(wake_sleeper_q, waiter->task);
  17470. + else
  17471. + wake_q_add(wake_q, waiter->task);
  17472. }
  17473. /*
  17474. * Remove a waiter from a lock and give up
  17475. *
  17476. - * Must be called with lock->wait_lock held and
  17477. + * Must be called with lock->wait_lock held and interrupts disabled. I must
  17478. * have just failed to try_to_take_rt_mutex().
  17479. */
  17480. static void remove_waiter(struct rt_mutex *lock,
  17481. @@ -1017,13 +1470,12 @@
  17482. {
  17483. bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock));
  17484. struct task_struct *owner = rt_mutex_owner(lock);
  17485. - struct rt_mutex *next_lock;
  17486. - unsigned long flags;
  17487. + struct rt_mutex *next_lock = NULL;
  17488. - raw_spin_lock_irqsave(&current->pi_lock, flags);
  17489. + raw_spin_lock(&current->pi_lock);
  17490. rt_mutex_dequeue(lock, waiter);
  17491. current->pi_blocked_on = NULL;
  17492. - raw_spin_unlock_irqrestore(&current->pi_lock, flags);
  17493. + raw_spin_unlock(&current->pi_lock);
  17494. /*
  17495. * Only update priority if the waiter was the highest priority
  17496. @@ -1032,7 +1484,7 @@
  17497. if (!owner || !is_top_waiter)
  17498. return;
  17499. - raw_spin_lock_irqsave(&owner->pi_lock, flags);
  17500. + raw_spin_lock(&owner->pi_lock);
  17501. rt_mutex_dequeue_pi(owner, waiter);
  17502. @@ -1042,9 +1494,10 @@
  17503. __rt_mutex_adjust_prio(owner);
  17504. /* Store the lock on which owner is blocked or NULL */
  17505. - next_lock = task_blocked_on_lock(owner);
  17506. + if (rt_mutex_real_waiter(owner->pi_blocked_on))
  17507. + next_lock = task_blocked_on_lock(owner);
  17508. - raw_spin_unlock_irqrestore(&owner->pi_lock, flags);
  17509. + raw_spin_unlock(&owner->pi_lock);
  17510. /*
  17511. * Don't walk the chain, if the owner task is not blocked
  17512. @@ -1056,12 +1509,12 @@
  17513. /* gets dropped in rt_mutex_adjust_prio_chain()! */
  17514. get_task_struct(owner);
  17515. - raw_spin_unlock(&lock->wait_lock);
  17516. + raw_spin_unlock_irq(&lock->wait_lock);
  17517. rt_mutex_adjust_prio_chain(owner, RT_MUTEX_MIN_CHAINWALK, lock,
  17518. next_lock, NULL, current);
  17519. - raw_spin_lock(&lock->wait_lock);
  17520. + raw_spin_lock_irq(&lock->wait_lock);
  17521. }
  17522. /*
  17523. @@ -1078,17 +1531,17 @@
  17524. raw_spin_lock_irqsave(&task->pi_lock, flags);
  17525. waiter = task->pi_blocked_on;
  17526. - if (!waiter || (waiter->prio == task->prio &&
  17527. + if (!rt_mutex_real_waiter(waiter) || (waiter->prio == task->prio &&
  17528. !dl_prio(task->prio))) {
  17529. raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  17530. return;
  17531. }
  17532. next_lock = waiter->lock;
  17533. - raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  17534. /* gets dropped in rt_mutex_adjust_prio_chain()! */
  17535. get_task_struct(task);
  17536. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  17537. rt_mutex_adjust_prio_chain(task, RT_MUTEX_MIN_CHAINWALK, NULL,
  17538. next_lock, NULL, task);
  17539. }
  17540. @@ -1097,16 +1550,17 @@
  17541. * __rt_mutex_slowlock() - Perform the wait-wake-try-to-take loop
  17542. * @lock: the rt_mutex to take
  17543. * @state: the state the task should block in (TASK_INTERRUPTIBLE
  17544. - * or TASK_UNINTERRUPTIBLE)
  17545. + * or TASK_UNINTERRUPTIBLE)
  17546. * @timeout: the pre-initialized and started timer, or NULL for none
  17547. * @waiter: the pre-initialized rt_mutex_waiter
  17548. *
  17549. - * lock->wait_lock must be held by the caller.
  17550. + * Must be called with lock->wait_lock held and interrupts disabled
  17551. */
  17552. static int __sched
  17553. __rt_mutex_slowlock(struct rt_mutex *lock, int state,
  17554. struct hrtimer_sleeper *timeout,
  17555. - struct rt_mutex_waiter *waiter)
  17556. + struct rt_mutex_waiter *waiter,
  17557. + struct ww_acquire_ctx *ww_ctx)
  17558. {
  17559. int ret = 0;
  17560. @@ -1129,13 +1583,19 @@
  17561. break;
  17562. }
  17563. - raw_spin_unlock(&lock->wait_lock);
  17564. + if (ww_ctx && ww_ctx->acquired > 0) {
  17565. + ret = __mutex_lock_check_stamp(lock, ww_ctx);
  17566. + if (ret)
  17567. + break;
  17568. + }
  17569. +
  17570. + raw_spin_unlock_irq(&lock->wait_lock);
  17571. debug_rt_mutex_print_deadlock(waiter);
  17572. schedule();
  17573. - raw_spin_lock(&lock->wait_lock);
  17574. + raw_spin_lock_irq(&lock->wait_lock);
  17575. set_current_state(state);
  17576. }
  17577. @@ -1163,26 +1623,112 @@
  17578. }
  17579. }
  17580. +static __always_inline void ww_mutex_lock_acquired(struct ww_mutex *ww,
  17581. + struct ww_acquire_ctx *ww_ctx)
  17582. +{
  17583. +#ifdef CONFIG_DEBUG_MUTEXES
  17584. + /*
  17585. + * If this WARN_ON triggers, you used ww_mutex_lock to acquire,
  17586. + * but released with a normal mutex_unlock in this call.
  17587. + *
  17588. + * This should never happen, always use ww_mutex_unlock.
  17589. + */
  17590. + DEBUG_LOCKS_WARN_ON(ww->ctx);
  17591. +
  17592. + /*
  17593. + * Not quite done after calling ww_acquire_done() ?
  17594. + */
  17595. + DEBUG_LOCKS_WARN_ON(ww_ctx->done_acquire);
  17596. +
  17597. + if (ww_ctx->contending_lock) {
  17598. + /*
  17599. + * After -EDEADLK you tried to
  17600. + * acquire a different ww_mutex? Bad!
  17601. + */
  17602. + DEBUG_LOCKS_WARN_ON(ww_ctx->contending_lock != ww);
  17603. +
  17604. + /*
  17605. + * You called ww_mutex_lock after receiving -EDEADLK,
  17606. + * but 'forgot' to unlock everything else first?
  17607. + */
  17608. + DEBUG_LOCKS_WARN_ON(ww_ctx->acquired > 0);
  17609. + ww_ctx->contending_lock = NULL;
  17610. + }
  17611. +
  17612. + /*
  17613. + * Naughty, using a different class will lead to undefined behavior!
  17614. + */
  17615. + DEBUG_LOCKS_WARN_ON(ww_ctx->ww_class != ww->ww_class);
  17616. +#endif
  17617. + ww_ctx->acquired++;
  17618. +}
  17619. +
  17620. +#ifdef CONFIG_PREEMPT_RT_FULL
  17621. +static void ww_mutex_account_lock(struct rt_mutex *lock,
  17622. + struct ww_acquire_ctx *ww_ctx)
  17623. +{
  17624. + struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock);
  17625. + struct rt_mutex_waiter *waiter, *n;
  17626. +
  17627. + /*
  17628. + * This branch gets optimized out for the common case,
  17629. + * and is only important for ww_mutex_lock.
  17630. + */
  17631. + ww_mutex_lock_acquired(ww, ww_ctx);
  17632. + ww->ctx = ww_ctx;
  17633. +
  17634. + /*
  17635. + * Give any possible sleeping processes the chance to wake up,
  17636. + * so they can recheck if they have to back off.
  17637. + */
  17638. + rbtree_postorder_for_each_entry_safe(waiter, n, &lock->waiters,
  17639. + tree_entry) {
  17640. + /* XXX debug rt mutex waiter wakeup */
  17641. +
  17642. + BUG_ON(waiter->lock != lock);
  17643. + rt_mutex_wake_waiter(waiter);
  17644. + }
  17645. +}
  17646. +
  17647. +#else
  17648. +
  17649. +static void ww_mutex_account_lock(struct rt_mutex *lock,
  17650. + struct ww_acquire_ctx *ww_ctx)
  17651. +{
  17652. + BUG();
  17653. +}
  17654. +#endif
  17655. +
  17656. /*
  17657. * Slow path lock function:
  17658. */
  17659. static int __sched
  17660. rt_mutex_slowlock(struct rt_mutex *lock, int state,
  17661. struct hrtimer_sleeper *timeout,
  17662. - enum rtmutex_chainwalk chwalk)
  17663. + enum rtmutex_chainwalk chwalk,
  17664. + struct ww_acquire_ctx *ww_ctx)
  17665. {
  17666. struct rt_mutex_waiter waiter;
  17667. + unsigned long flags;
  17668. int ret = 0;
  17669. - debug_rt_mutex_init_waiter(&waiter);
  17670. - RB_CLEAR_NODE(&waiter.pi_tree_entry);
  17671. - RB_CLEAR_NODE(&waiter.tree_entry);
  17672. + rt_mutex_init_waiter(&waiter, false);
  17673. - raw_spin_lock(&lock->wait_lock);
  17674. + /*
  17675. + * Technically we could use raw_spin_[un]lock_irq() here, but this can
  17676. + * be called in early boot if the cmpxchg() fast path is disabled
  17677. + * (debug, no architecture support). In this case we will acquire the
  17678. + * rtmutex with lock->wait_lock held. But we cannot unconditionally
  17679. + * enable interrupts in that early boot case. So we need to use the
  17680. + * irqsave/restore variants.
  17681. + */
  17682. + raw_spin_lock_irqsave(&lock->wait_lock, flags);
  17683. /* Try to acquire the lock again: */
  17684. if (try_to_take_rt_mutex(lock, current, NULL)) {
  17685. - raw_spin_unlock(&lock->wait_lock);
  17686. + if (ww_ctx)
  17687. + ww_mutex_account_lock(lock, ww_ctx);
  17688. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  17689. return 0;
  17690. }
  17691. @@ -1196,13 +1742,23 @@
  17692. if (likely(!ret))
  17693. /* sleep on the mutex */
  17694. - ret = __rt_mutex_slowlock(lock, state, timeout, &waiter);
  17695. + ret = __rt_mutex_slowlock(lock, state, timeout, &waiter,
  17696. + ww_ctx);
  17697. + else if (ww_ctx) {
  17698. + /* ww_mutex received EDEADLK, let it become EALREADY */
  17699. + ret = __mutex_lock_check_stamp(lock, ww_ctx);
  17700. + BUG_ON(!ret);
  17701. + }
  17702. if (unlikely(ret)) {
  17703. __set_current_state(TASK_RUNNING);
  17704. if (rt_mutex_has_waiters(lock))
  17705. remove_waiter(lock, &waiter);
  17706. - rt_mutex_handle_deadlock(ret, chwalk, &waiter);
  17707. + /* ww_mutex want to report EDEADLK/EALREADY, let them */
  17708. + if (!ww_ctx)
  17709. + rt_mutex_handle_deadlock(ret, chwalk, &waiter);
  17710. + } else if (ww_ctx) {
  17711. + ww_mutex_account_lock(lock, ww_ctx);
  17712. }
  17713. /*
  17714. @@ -1211,7 +1767,7 @@
  17715. */
  17716. fixup_rt_mutex_waiters(lock);
  17717. - raw_spin_unlock(&lock->wait_lock);
  17718. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  17719. /* Remove pending timer: */
  17720. if (unlikely(timeout))
  17721. @@ -1227,6 +1783,7 @@
  17722. */
  17723. static inline int rt_mutex_slowtrylock(struct rt_mutex *lock)
  17724. {
  17725. + unsigned long flags;
  17726. int ret;
  17727. /*
  17728. @@ -1238,10 +1795,10 @@
  17729. return 0;
  17730. /*
  17731. - * The mutex has currently no owner. Lock the wait lock and
  17732. - * try to acquire the lock.
  17733. + * The mutex has currently no owner. Lock the wait lock and try to
  17734. + * acquire the lock. We use irqsave here to support early boot calls.
  17735. */
  17736. - raw_spin_lock(&lock->wait_lock);
  17737. + raw_spin_lock_irqsave(&lock->wait_lock, flags);
  17738. ret = try_to_take_rt_mutex(lock, current, NULL);
  17739. @@ -1251,7 +1808,7 @@
  17740. */
  17741. fixup_rt_mutex_waiters(lock);
  17742. - raw_spin_unlock(&lock->wait_lock);
  17743. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  17744. return ret;
  17745. }
  17746. @@ -1261,9 +1818,13 @@
  17747. * Return whether the current task needs to undo a potential priority boosting.
  17748. */
  17749. static bool __sched rt_mutex_slowunlock(struct rt_mutex *lock,
  17750. - struct wake_q_head *wake_q)
  17751. + struct wake_q_head *wake_q,
  17752. + struct wake_q_head *wake_sleeper_q)
  17753. {
  17754. - raw_spin_lock(&lock->wait_lock);
  17755. + unsigned long flags;
  17756. +
  17757. + /* irqsave required to support early boot calls */
  17758. + raw_spin_lock_irqsave(&lock->wait_lock, flags);
  17759. debug_rt_mutex_unlock(lock);
  17760. @@ -1302,10 +1863,10 @@
  17761. */
  17762. while (!rt_mutex_has_waiters(lock)) {
  17763. /* Drops lock->wait_lock ! */
  17764. - if (unlock_rt_mutex_safe(lock) == true)
  17765. + if (unlock_rt_mutex_safe(lock, flags) == true)
  17766. return false;
  17767. /* Relock the rtmutex and try again */
  17768. - raw_spin_lock(&lock->wait_lock);
  17769. + raw_spin_lock_irqsave(&lock->wait_lock, flags);
  17770. }
  17771. /*
  17772. @@ -1314,9 +1875,9 @@
  17773. *
  17774. * Queue the next waiter for wakeup once we release the wait_lock.
  17775. */
  17776. - mark_wakeup_next_waiter(wake_q, lock);
  17777. + mark_wakeup_next_waiter(wake_q, wake_sleeper_q, lock);
  17778. - raw_spin_unlock(&lock->wait_lock);
  17779. + raw_spin_unlock_irqrestore(&lock->wait_lock, flags);
  17780. /* check PI boosting */
  17781. return true;
  17782. @@ -1330,31 +1891,36 @@
  17783. */
  17784. static inline int
  17785. rt_mutex_fastlock(struct rt_mutex *lock, int state,
  17786. + struct ww_acquire_ctx *ww_ctx,
  17787. int (*slowfn)(struct rt_mutex *lock, int state,
  17788. struct hrtimer_sleeper *timeout,
  17789. - enum rtmutex_chainwalk chwalk))
  17790. + enum rtmutex_chainwalk chwalk,
  17791. + struct ww_acquire_ctx *ww_ctx))
  17792. {
  17793. if (likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) {
  17794. rt_mutex_deadlock_account_lock(lock, current);
  17795. return 0;
  17796. } else
  17797. - return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK);
  17798. + return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK,
  17799. + ww_ctx);
  17800. }
  17801. static inline int
  17802. rt_mutex_timed_fastlock(struct rt_mutex *lock, int state,
  17803. struct hrtimer_sleeper *timeout,
  17804. enum rtmutex_chainwalk chwalk,
  17805. + struct ww_acquire_ctx *ww_ctx,
  17806. int (*slowfn)(struct rt_mutex *lock, int state,
  17807. struct hrtimer_sleeper *timeout,
  17808. - enum rtmutex_chainwalk chwalk))
  17809. + enum rtmutex_chainwalk chwalk,
  17810. + struct ww_acquire_ctx *ww_ctx))
  17811. {
  17812. if (chwalk == RT_MUTEX_MIN_CHAINWALK &&
  17813. likely(rt_mutex_cmpxchg_acquire(lock, NULL, current))) {
  17814. rt_mutex_deadlock_account_lock(lock, current);
  17815. return 0;
  17816. } else
  17817. - return slowfn(lock, state, timeout, chwalk);
  17818. + return slowfn(lock, state, timeout, chwalk, ww_ctx);
  17819. }
  17820. static inline int
  17821. @@ -1371,17 +1937,20 @@
  17822. static inline void
  17823. rt_mutex_fastunlock(struct rt_mutex *lock,
  17824. bool (*slowfn)(struct rt_mutex *lock,
  17825. - struct wake_q_head *wqh))
  17826. + struct wake_q_head *wqh,
  17827. + struct wake_q_head *wq_sleeper))
  17828. {
  17829. WAKE_Q(wake_q);
  17830. + WAKE_Q(wake_sleeper_q);
  17831. if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) {
  17832. rt_mutex_deadlock_account_unlock(current);
  17833. } else {
  17834. - bool deboost = slowfn(lock, &wake_q);
  17835. + bool deboost = slowfn(lock, &wake_q, &wake_sleeper_q);
  17836. wake_up_q(&wake_q);
  17837. + wake_up_q_sleeper(&wake_sleeper_q);
  17838. /* Undo pi boosting if necessary: */
  17839. if (deboost)
  17840. @@ -1398,7 +1967,7 @@
  17841. {
  17842. might_sleep();
  17843. - rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
  17844. + rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, NULL, rt_mutex_slowlock);
  17845. }
  17846. EXPORT_SYMBOL_GPL(rt_mutex_lock);
  17847. @@ -1415,7 +1984,7 @@
  17848. {
  17849. might_sleep();
  17850. - return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock);
  17851. + return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, NULL, rt_mutex_slowlock);
  17852. }
  17853. EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
  17854. @@ -1428,11 +1997,30 @@
  17855. might_sleep();
  17856. return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
  17857. - RT_MUTEX_FULL_CHAINWALK,
  17858. + RT_MUTEX_FULL_CHAINWALK, NULL,
  17859. rt_mutex_slowlock);
  17860. }
  17861. /**
  17862. + * rt_mutex_lock_killable - lock a rt_mutex killable
  17863. + *
  17864. + * @lock: the rt_mutex to be locked
  17865. + * @detect_deadlock: deadlock detection on/off
  17866. + *
  17867. + * Returns:
  17868. + * 0 on success
  17869. + * -EINTR when interrupted by a signal
  17870. + * -EDEADLK when the lock would deadlock (when deadlock detection is on)
  17871. + */
  17872. +int __sched rt_mutex_lock_killable(struct rt_mutex *lock)
  17873. +{
  17874. + might_sleep();
  17875. +
  17876. + return rt_mutex_fastlock(lock, TASK_KILLABLE, NULL, rt_mutex_slowlock);
  17877. +}
  17878. +EXPORT_SYMBOL_GPL(rt_mutex_lock_killable);
  17879. +
  17880. +/**
  17881. * rt_mutex_timed_lock - lock a rt_mutex interruptible
  17882. * the timeout structure is provided
  17883. * by the caller
  17884. @@ -1452,6 +2040,7 @@
  17885. return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
  17886. RT_MUTEX_MIN_CHAINWALK,
  17887. + NULL,
  17888. rt_mutex_slowlock);
  17889. }
  17890. EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
  17891. @@ -1469,7 +2058,11 @@
  17892. */
  17893. int __sched rt_mutex_trylock(struct rt_mutex *lock)
  17894. {
  17895. +#ifdef CONFIG_PREEMPT_RT_FULL
  17896. + if (WARN_ON_ONCE(in_irq() || in_nmi()))
  17897. +#else
  17898. if (WARN_ON(in_irq() || in_nmi() || in_serving_softirq()))
  17899. +#endif
  17900. return 0;
  17901. return rt_mutex_fasttrylock(lock, rt_mutex_slowtrylock);
  17902. @@ -1495,13 +2088,14 @@
  17903. * required or not.
  17904. */
  17905. bool __sched rt_mutex_futex_unlock(struct rt_mutex *lock,
  17906. - struct wake_q_head *wqh)
  17907. + struct wake_q_head *wqh,
  17908. + struct wake_q_head *wq_sleeper)
  17909. {
  17910. if (likely(rt_mutex_cmpxchg_release(lock, current, NULL))) {
  17911. rt_mutex_deadlock_account_unlock(current);
  17912. return false;
  17913. }
  17914. - return rt_mutex_slowunlock(lock, wqh);
  17915. + return rt_mutex_slowunlock(lock, wqh, wq_sleeper);
  17916. }
  17917. /**
  17918. @@ -1534,13 +2128,12 @@
  17919. void __rt_mutex_init(struct rt_mutex *lock, const char *name)
  17920. {
  17921. lock->owner = NULL;
  17922. - raw_spin_lock_init(&lock->wait_lock);
  17923. lock->waiters = RB_ROOT;
  17924. lock->waiters_leftmost = NULL;
  17925. debug_rt_mutex_init(lock, name);
  17926. }
  17927. -EXPORT_SYMBOL_GPL(__rt_mutex_init);
  17928. +EXPORT_SYMBOL(__rt_mutex_init);
  17929. /**
  17930. * rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a
  17931. @@ -1555,7 +2148,7 @@
  17932. void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
  17933. struct task_struct *proxy_owner)
  17934. {
  17935. - __rt_mutex_init(lock, NULL);
  17936. + rt_mutex_init(lock);
  17937. debug_rt_mutex_proxy_lock(lock, proxy_owner);
  17938. rt_mutex_set_owner(lock, proxy_owner);
  17939. rt_mutex_deadlock_account_lock(lock, proxy_owner);
  17940. @@ -1596,13 +2189,42 @@
  17941. {
  17942. int ret;
  17943. - raw_spin_lock(&lock->wait_lock);
  17944. + raw_spin_lock_irq(&lock->wait_lock);
  17945. if (try_to_take_rt_mutex(lock, task, NULL)) {
  17946. - raw_spin_unlock(&lock->wait_lock);
  17947. + raw_spin_unlock_irq(&lock->wait_lock);
  17948. return 1;
  17949. }
  17950. +#ifdef CONFIG_PREEMPT_RT_FULL
  17951. + /*
  17952. + * In PREEMPT_RT there's an added race.
  17953. + * If the task, that we are about to requeue, times out,
  17954. + * it can set the PI_WAKEUP_INPROGRESS. This tells the requeue
  17955. + * to skip this task. But right after the task sets
  17956. + * its pi_blocked_on to PI_WAKEUP_INPROGRESS it can then
  17957. + * block on the spin_lock(&hb->lock), which in RT is an rtmutex.
  17958. + * This will replace the PI_WAKEUP_INPROGRESS with the actual
  17959. + * lock that it blocks on. We *must not* place this task
  17960. + * on this proxy lock in that case.
  17961. + *
  17962. + * To prevent this race, we first take the task's pi_lock
  17963. + * and check if it has updated its pi_blocked_on. If it has,
  17964. + * we assume that it woke up and we return -EAGAIN.
  17965. + * Otherwise, we set the task's pi_blocked_on to
  17966. + * PI_REQUEUE_INPROGRESS, so that if the task is waking up
  17967. + * it will know that we are in the process of requeuing it.
  17968. + */
  17969. + raw_spin_lock(&task->pi_lock);
  17970. + if (task->pi_blocked_on) {
  17971. + raw_spin_unlock(&task->pi_lock);
  17972. + raw_spin_unlock_irq(&lock->wait_lock);
  17973. + return -EAGAIN;
  17974. + }
  17975. + task->pi_blocked_on = PI_REQUEUE_INPROGRESS;
  17976. + raw_spin_unlock(&task->pi_lock);
  17977. +#endif
  17978. +
  17979. /* We enforce deadlock detection for futexes */
  17980. ret = task_blocks_on_rt_mutex(lock, waiter, task,
  17981. RT_MUTEX_FULL_CHAINWALK);
  17982. @@ -1617,10 +2239,10 @@
  17983. ret = 0;
  17984. }
  17985. - if (unlikely(ret))
  17986. + if (ret && rt_mutex_has_waiters(lock))
  17987. remove_waiter(lock, waiter);
  17988. - raw_spin_unlock(&lock->wait_lock);
  17989. + raw_spin_unlock_irq(&lock->wait_lock);
  17990. debug_rt_mutex_print_deadlock(waiter);
  17991. @@ -1668,12 +2290,12 @@
  17992. {
  17993. int ret;
  17994. - raw_spin_lock(&lock->wait_lock);
  17995. + raw_spin_lock_irq(&lock->wait_lock);
  17996. set_current_state(TASK_INTERRUPTIBLE);
  17997. /* sleep on the mutex */
  17998. - ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter);
  17999. + ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter, NULL);
  18000. if (unlikely(ret))
  18001. remove_waiter(lock, waiter);
  18002. @@ -1684,7 +2306,93 @@
  18003. */
  18004. fixup_rt_mutex_waiters(lock);
  18005. - raw_spin_unlock(&lock->wait_lock);
  18006. + raw_spin_unlock_irq(&lock->wait_lock);
  18007. return ret;
  18008. }
  18009. +
  18010. +static inline int
  18011. +ww_mutex_deadlock_injection(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
  18012. +{
  18013. +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
  18014. + unsigned tmp;
  18015. +
  18016. + if (ctx->deadlock_inject_countdown-- == 0) {
  18017. + tmp = ctx->deadlock_inject_interval;
  18018. + if (tmp > UINT_MAX/4)
  18019. + tmp = UINT_MAX;
  18020. + else
  18021. + tmp = tmp*2 + tmp + tmp/2;
  18022. +
  18023. + ctx->deadlock_inject_interval = tmp;
  18024. + ctx->deadlock_inject_countdown = tmp;
  18025. + ctx->contending_lock = lock;
  18026. +
  18027. + ww_mutex_unlock(lock);
  18028. +
  18029. + return -EDEADLK;
  18030. + }
  18031. +#endif
  18032. +
  18033. + return 0;
  18034. +}
  18035. +
  18036. +#ifdef CONFIG_PREEMPT_RT_FULL
  18037. +int __sched
  18038. +__ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ww_ctx)
  18039. +{
  18040. + int ret;
  18041. +
  18042. + might_sleep();
  18043. +
  18044. + mutex_acquire_nest(&lock->base.dep_map, 0, 0, &ww_ctx->dep_map, _RET_IP_);
  18045. + ret = rt_mutex_slowlock(&lock->base.lock, TASK_INTERRUPTIBLE, NULL, 0, ww_ctx);
  18046. + if (ret)
  18047. + mutex_release(&lock->base.dep_map, 1, _RET_IP_);
  18048. + else if (!ret && ww_ctx->acquired > 1)
  18049. + return ww_mutex_deadlock_injection(lock, ww_ctx);
  18050. +
  18051. + return ret;
  18052. +}
  18053. +EXPORT_SYMBOL_GPL(__ww_mutex_lock_interruptible);
  18054. +
  18055. +int __sched
  18056. +__ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ww_ctx)
  18057. +{
  18058. + int ret;
  18059. +
  18060. + might_sleep();
  18061. +
  18062. + mutex_acquire_nest(&lock->base.dep_map, 0, 0, &ww_ctx->dep_map, _RET_IP_);
  18063. + ret = rt_mutex_slowlock(&lock->base.lock, TASK_UNINTERRUPTIBLE, NULL, 0, ww_ctx);
  18064. + if (ret)
  18065. + mutex_release(&lock->base.dep_map, 1, _RET_IP_);
  18066. + else if (!ret && ww_ctx->acquired > 1)
  18067. + return ww_mutex_deadlock_injection(lock, ww_ctx);
  18068. +
  18069. + return ret;
  18070. +}
  18071. +EXPORT_SYMBOL_GPL(__ww_mutex_lock);
  18072. +
  18073. +void __sched ww_mutex_unlock(struct ww_mutex *lock)
  18074. +{
  18075. + int nest = !!lock->ctx;
  18076. +
  18077. + /*
  18078. + * The unlocking fastpath is the 0->1 transition from 'locked'
  18079. + * into 'unlocked' state:
  18080. + */
  18081. + if (nest) {
  18082. +#ifdef CONFIG_DEBUG_MUTEXES
  18083. + DEBUG_LOCKS_WARN_ON(!lock->ctx->acquired);
  18084. +#endif
  18085. + if (lock->ctx->acquired > 0)
  18086. + lock->ctx->acquired--;
  18087. + lock->ctx = NULL;
  18088. + }
  18089. +
  18090. + mutex_release(&lock->base.dep_map, nest, _RET_IP_);
  18091. + rt_mutex_unlock(&lock->base.lock);
  18092. +}
  18093. +EXPORT_SYMBOL(ww_mutex_unlock);
  18094. +#endif
  18095. diff -Nur linux-4.4.13.orig/kernel/locking/rtmutex_common.h linux-4.4.13/kernel/locking/rtmutex_common.h
  18096. --- linux-4.4.13.orig/kernel/locking/rtmutex_common.h 2016-06-08 03:14:51.000000000 +0200
  18097. +++ linux-4.4.13/kernel/locking/rtmutex_common.h 2016-06-22 21:55:08.050523867 +0200
  18098. @@ -27,6 +27,7 @@
  18099. struct rb_node pi_tree_entry;
  18100. struct task_struct *task;
  18101. struct rt_mutex *lock;
  18102. + bool savestate;
  18103. #ifdef CONFIG_DEBUG_RT_MUTEXES
  18104. unsigned long ip;
  18105. struct pid *deadlock_task_pid;
  18106. @@ -97,6 +98,9 @@
  18107. /*
  18108. * PI-futex support (proxy locking functions, etc.):
  18109. */
  18110. +#define PI_WAKEUP_INPROGRESS ((struct rt_mutex_waiter *) 1)
  18111. +#define PI_REQUEUE_INPROGRESS ((struct rt_mutex_waiter *) 2)
  18112. +
  18113. extern struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock);
  18114. extern void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
  18115. struct task_struct *proxy_owner);
  18116. @@ -110,7 +114,8 @@
  18117. struct rt_mutex_waiter *waiter);
  18118. extern int rt_mutex_timed_futex_lock(struct rt_mutex *l, struct hrtimer_sleeper *to);
  18119. extern bool rt_mutex_futex_unlock(struct rt_mutex *lock,
  18120. - struct wake_q_head *wqh);
  18121. + struct wake_q_head *wqh,
  18122. + struct wake_q_head *wq_sleeper);
  18123. extern void rt_mutex_adjust_prio(struct task_struct *task);
  18124. #ifdef CONFIG_DEBUG_RT_MUTEXES
  18125. @@ -119,4 +124,14 @@
  18126. # include "rtmutex.h"
  18127. #endif
  18128. +static inline void
  18129. +rt_mutex_init_waiter(struct rt_mutex_waiter *waiter, bool savestate)
  18130. +{
  18131. + debug_rt_mutex_init_waiter(waiter);
  18132. + waiter->task = NULL;
  18133. + waiter->savestate = savestate;
  18134. + RB_CLEAR_NODE(&waiter->pi_tree_entry);
  18135. + RB_CLEAR_NODE(&waiter->tree_entry);
  18136. +}
  18137. +
  18138. #endif
  18139. diff -Nur linux-4.4.13.orig/kernel/locking/spinlock.c linux-4.4.13/kernel/locking/spinlock.c
  18140. --- linux-4.4.13.orig/kernel/locking/spinlock.c 2016-06-08 03:14:51.000000000 +0200
  18141. +++ linux-4.4.13/kernel/locking/spinlock.c 2016-06-22 21:55:08.050523867 +0200
  18142. @@ -124,8 +124,11 @@
  18143. * __[spin|read|write]_lock_bh()
  18144. */
  18145. BUILD_LOCK_OPS(spin, raw_spinlock);
  18146. +
  18147. +#ifndef CONFIG_PREEMPT_RT_FULL
  18148. BUILD_LOCK_OPS(read, rwlock);
  18149. BUILD_LOCK_OPS(write, rwlock);
  18150. +#endif
  18151. #endif
  18152. @@ -209,6 +212,8 @@
  18153. EXPORT_SYMBOL(_raw_spin_unlock_bh);
  18154. #endif
  18155. +#ifndef CONFIG_PREEMPT_RT_FULL
  18156. +
  18157. #ifndef CONFIG_INLINE_READ_TRYLOCK
  18158. int __lockfunc _raw_read_trylock(rwlock_t *lock)
  18159. {
  18160. @@ -353,6 +358,8 @@
  18161. EXPORT_SYMBOL(_raw_write_unlock_bh);
  18162. #endif
  18163. +#endif /* !PREEMPT_RT_FULL */
  18164. +
  18165. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  18166. void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass)
  18167. diff -Nur linux-4.4.13.orig/kernel/locking/spinlock_debug.c linux-4.4.13/kernel/locking/spinlock_debug.c
  18168. --- linux-4.4.13.orig/kernel/locking/spinlock_debug.c 2016-06-08 03:14:51.000000000 +0200
  18169. +++ linux-4.4.13/kernel/locking/spinlock_debug.c 2016-06-22 21:55:08.050523867 +0200
  18170. @@ -31,6 +31,7 @@
  18171. EXPORT_SYMBOL(__raw_spin_lock_init);
  18172. +#ifndef CONFIG_PREEMPT_RT_FULL
  18173. void __rwlock_init(rwlock_t *lock, const char *name,
  18174. struct lock_class_key *key)
  18175. {
  18176. @@ -48,6 +49,7 @@
  18177. }
  18178. EXPORT_SYMBOL(__rwlock_init);
  18179. +#endif
  18180. static void spin_dump(raw_spinlock_t *lock, const char *msg)
  18181. {
  18182. @@ -159,6 +161,7 @@
  18183. arch_spin_unlock(&lock->raw_lock);
  18184. }
  18185. +#ifndef CONFIG_PREEMPT_RT_FULL
  18186. static void rwlock_bug(rwlock_t *lock, const char *msg)
  18187. {
  18188. if (!debug_locks_off())
  18189. @@ -300,3 +303,5 @@
  18190. debug_write_unlock(lock);
  18191. arch_write_unlock(&lock->raw_lock);
  18192. }
  18193. +
  18194. +#endif
  18195. diff -Nur linux-4.4.13.orig/kernel/panic.c linux-4.4.13/kernel/panic.c
  18196. --- linux-4.4.13.orig/kernel/panic.c 2016-06-08 03:14:51.000000000 +0200
  18197. +++ linux-4.4.13/kernel/panic.c 2016-06-22 21:55:08.050523867 +0200
  18198. @@ -61,6 +61,37 @@
  18199. cpu_relax();
  18200. }
  18201. +/*
  18202. + * Stop ourselves in NMI context if another CPU has already panicked. Arch code
  18203. + * may override this to prepare for crash dumping, e.g. save regs info.
  18204. + */
  18205. +void __weak nmi_panic_self_stop(struct pt_regs *regs)
  18206. +{
  18207. + panic_smp_self_stop();
  18208. +}
  18209. +
  18210. +atomic_t panic_cpu = ATOMIC_INIT(PANIC_CPU_INVALID);
  18211. +
  18212. +/*
  18213. + * A variant of panic() called from NMI context. We return if we've already
  18214. + * panicked on this CPU. If another CPU already panicked, loop in
  18215. + * nmi_panic_self_stop() which can provide architecture dependent code such
  18216. + * as saving register state for crash dump.
  18217. + */
  18218. +void nmi_panic(struct pt_regs *regs, const char *msg)
  18219. +{
  18220. + int old_cpu, cpu;
  18221. +
  18222. + cpu = raw_smp_processor_id();
  18223. + old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, cpu);
  18224. +
  18225. + if (old_cpu == PANIC_CPU_INVALID)
  18226. + panic("%s", msg);
  18227. + else if (old_cpu != cpu)
  18228. + nmi_panic_self_stop(regs);
  18229. +}
  18230. +EXPORT_SYMBOL(nmi_panic);
  18231. +
  18232. /**
  18233. * panic - halt the system
  18234. * @fmt: The text string to print
  18235. @@ -71,17 +102,17 @@
  18236. */
  18237. void panic(const char *fmt, ...)
  18238. {
  18239. - static DEFINE_SPINLOCK(panic_lock);
  18240. static char buf[1024];
  18241. va_list args;
  18242. long i, i_next = 0;
  18243. int state = 0;
  18244. + int old_cpu, this_cpu;
  18245. /*
  18246. * Disable local interrupts. This will prevent panic_smp_self_stop
  18247. * from deadlocking the first cpu that invokes the panic, since
  18248. * there is nothing to prevent an interrupt handler (that runs
  18249. - * after the panic_lock is acquired) from invoking panic again.
  18250. + * after setting panic_cpu) from invoking panic() again.
  18251. */
  18252. local_irq_disable();
  18253. @@ -94,8 +125,16 @@
  18254. * multiple parallel invocations of panic, all other CPUs either
  18255. * stop themself or will wait until they are stopped by the 1st CPU
  18256. * with smp_send_stop().
  18257. + *
  18258. + * `old_cpu == PANIC_CPU_INVALID' means this is the 1st CPU which
  18259. + * comes here, so go ahead.
  18260. + * `old_cpu == this_cpu' means we came from nmi_panic() which sets
  18261. + * panic_cpu to this CPU. In this case, this is also the 1st CPU.
  18262. */
  18263. - if (!spin_trylock(&panic_lock))
  18264. + this_cpu = raw_smp_processor_id();
  18265. + old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, this_cpu);
  18266. +
  18267. + if (old_cpu != PANIC_CPU_INVALID && old_cpu != this_cpu)
  18268. panic_smp_self_stop();
  18269. console_verbose();
  18270. @@ -400,9 +439,11 @@
  18271. static int init_oops_id(void)
  18272. {
  18273. +#ifndef CONFIG_PREEMPT_RT_FULL
  18274. if (!oops_id)
  18275. get_random_bytes(&oops_id, sizeof(oops_id));
  18276. else
  18277. +#endif
  18278. oops_id++;
  18279. return 0;
  18280. diff -Nur linux-4.4.13.orig/kernel/power/hibernate.c linux-4.4.13/kernel/power/hibernate.c
  18281. --- linux-4.4.13.orig/kernel/power/hibernate.c 2016-06-08 03:14:51.000000000 +0200
  18282. +++ linux-4.4.13/kernel/power/hibernate.c 2016-06-22 21:55:08.054523867 +0200
  18283. @@ -285,6 +285,8 @@
  18284. local_irq_disable();
  18285. + system_state = SYSTEM_SUSPEND;
  18286. +
  18287. error = syscore_suspend();
  18288. if (error) {
  18289. printk(KERN_ERR "PM: Some system devices failed to power down, "
  18290. @@ -314,6 +316,7 @@
  18291. syscore_resume();
  18292. Enable_irqs:
  18293. + system_state = SYSTEM_RUNNING;
  18294. local_irq_enable();
  18295. Enable_cpus:
  18296. @@ -438,6 +441,7 @@
  18297. goto Enable_cpus;
  18298. local_irq_disable();
  18299. + system_state = SYSTEM_SUSPEND;
  18300. error = syscore_suspend();
  18301. if (error)
  18302. @@ -471,6 +475,7 @@
  18303. syscore_resume();
  18304. Enable_irqs:
  18305. + system_state = SYSTEM_RUNNING;
  18306. local_irq_enable();
  18307. Enable_cpus:
  18308. @@ -556,6 +561,7 @@
  18309. goto Enable_cpus;
  18310. local_irq_disable();
  18311. + system_state = SYSTEM_SUSPEND;
  18312. syscore_suspend();
  18313. if (pm_wakeup_pending()) {
  18314. error = -EAGAIN;
  18315. @@ -568,6 +574,7 @@
  18316. Power_up:
  18317. syscore_resume();
  18318. + system_state = SYSTEM_RUNNING;
  18319. local_irq_enable();
  18320. Enable_cpus:
  18321. @@ -642,6 +649,10 @@
  18322. cpu_relax();
  18323. }
  18324. +#ifndef CONFIG_SUSPEND
  18325. +bool pm_in_action;
  18326. +#endif
  18327. +
  18328. /**
  18329. * hibernate - Carry out system hibernation, including saving the image.
  18330. */
  18331. @@ -654,6 +665,8 @@
  18332. return -EPERM;
  18333. }
  18334. + pm_in_action = true;
  18335. +
  18336. lock_system_sleep();
  18337. /* The snapshot device should not be opened while we're running */
  18338. if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
  18339. @@ -719,6 +732,7 @@
  18340. atomic_inc(&snapshot_device_available);
  18341. Unlock:
  18342. unlock_system_sleep();
  18343. + pm_in_action = false;
  18344. return error;
  18345. }
  18346. diff -Nur linux-4.4.13.orig/kernel/power/suspend.c linux-4.4.13/kernel/power/suspend.c
  18347. --- linux-4.4.13.orig/kernel/power/suspend.c 2016-06-08 03:14:51.000000000 +0200
  18348. +++ linux-4.4.13/kernel/power/suspend.c 2016-06-22 21:55:08.054523867 +0200
  18349. @@ -359,6 +359,8 @@
  18350. arch_suspend_disable_irqs();
  18351. BUG_ON(!irqs_disabled());
  18352. + system_state = SYSTEM_SUSPEND;
  18353. +
  18354. error = syscore_suspend();
  18355. if (!error) {
  18356. *wakeup = pm_wakeup_pending();
  18357. @@ -375,6 +377,8 @@
  18358. syscore_resume();
  18359. }
  18360. + system_state = SYSTEM_RUNNING;
  18361. +
  18362. arch_suspend_enable_irqs();
  18363. BUG_ON(irqs_disabled());
  18364. @@ -518,6 +522,8 @@
  18365. return error;
  18366. }
  18367. +bool pm_in_action;
  18368. +
  18369. /**
  18370. * pm_suspend - Externally visible function for suspending the system.
  18371. * @state: System sleep state to enter.
  18372. @@ -532,6 +538,8 @@
  18373. if (state <= PM_SUSPEND_ON || state >= PM_SUSPEND_MAX)
  18374. return -EINVAL;
  18375. + pm_in_action = true;
  18376. +
  18377. error = enter_state(state);
  18378. if (error) {
  18379. suspend_stats.fail++;
  18380. @@ -539,6 +547,7 @@
  18381. } else {
  18382. suspend_stats.success++;
  18383. }
  18384. + pm_in_action = false;
  18385. return error;
  18386. }
  18387. EXPORT_SYMBOL(pm_suspend);
  18388. diff -Nur linux-4.4.13.orig/kernel/printk/printk.c linux-4.4.13/kernel/printk/printk.c
  18389. --- linux-4.4.13.orig/kernel/printk/printk.c 2016-06-08 03:14:51.000000000 +0200
  18390. +++ linux-4.4.13/kernel/printk/printk.c 2016-06-22 21:55:08.054523867 +0200
  18391. @@ -241,6 +241,65 @@
  18392. */
  18393. static DEFINE_RAW_SPINLOCK(logbuf_lock);
  18394. +#ifdef CONFIG_EARLY_PRINTK
  18395. +struct console *early_console;
  18396. +
  18397. +static void early_vprintk(const char *fmt, va_list ap)
  18398. +{
  18399. + if (early_console) {
  18400. + char buf[512];
  18401. + int n = vscnprintf(buf, sizeof(buf), fmt, ap);
  18402. +
  18403. + early_console->write(early_console, buf, n);
  18404. + }
  18405. +}
  18406. +
  18407. +asmlinkage void early_printk(const char *fmt, ...)
  18408. +{
  18409. + va_list ap;
  18410. +
  18411. + va_start(ap, fmt);
  18412. + early_vprintk(fmt, ap);
  18413. + va_end(ap);
  18414. +}
  18415. +
  18416. +/*
  18417. + * This is independent of any log levels - a global
  18418. + * kill switch that turns off all of printk.
  18419. + *
  18420. + * Used by the NMI watchdog if early-printk is enabled.
  18421. + */
  18422. +static bool __read_mostly printk_killswitch;
  18423. +
  18424. +static int __init force_early_printk_setup(char *str)
  18425. +{
  18426. + printk_killswitch = true;
  18427. + return 0;
  18428. +}
  18429. +early_param("force_early_printk", force_early_printk_setup);
  18430. +
  18431. +void printk_kill(void)
  18432. +{
  18433. + printk_killswitch = true;
  18434. +}
  18435. +
  18436. +#ifdef CONFIG_PRINTK
  18437. +static int forced_early_printk(const char *fmt, va_list ap)
  18438. +{
  18439. + if (!printk_killswitch)
  18440. + return 0;
  18441. + early_vprintk(fmt, ap);
  18442. + return 1;
  18443. +}
  18444. +#endif
  18445. +
  18446. +#else
  18447. +static inline int forced_early_printk(const char *fmt, va_list ap)
  18448. +{
  18449. + return 0;
  18450. +}
  18451. +#endif
  18452. +
  18453. #ifdef CONFIG_PRINTK
  18454. DECLARE_WAIT_QUEUE_HEAD(log_wait);
  18455. /* the next printk record to read by syslog(READ) or /proc/kmsg */
  18456. @@ -1203,6 +1262,7 @@
  18457. {
  18458. char *text;
  18459. int len = 0;
  18460. + int attempts = 0;
  18461. text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
  18462. if (!text)
  18463. @@ -1214,7 +1274,14 @@
  18464. u64 seq;
  18465. u32 idx;
  18466. enum log_flags prev;
  18467. -
  18468. + int num_msg;
  18469. +try_again:
  18470. + attempts++;
  18471. + if (attempts > 10) {
  18472. + len = -EBUSY;
  18473. + goto out;
  18474. + }
  18475. + num_msg = 0;
  18476. if (clear_seq < log_first_seq) {
  18477. /* messages are gone, move to first available one */
  18478. clear_seq = log_first_seq;
  18479. @@ -1235,6 +1302,14 @@
  18480. prev = msg->flags;
  18481. idx = log_next(idx);
  18482. seq++;
  18483. + num_msg++;
  18484. + if (num_msg > 5) {
  18485. + num_msg = 0;
  18486. + raw_spin_unlock_irq(&logbuf_lock);
  18487. + raw_spin_lock_irq(&logbuf_lock);
  18488. + if (clear_seq < log_first_seq)
  18489. + goto try_again;
  18490. + }
  18491. }
  18492. /* move first record forward until length fits into the buffer */
  18493. @@ -1248,6 +1323,14 @@
  18494. prev = msg->flags;
  18495. idx = log_next(idx);
  18496. seq++;
  18497. + num_msg++;
  18498. + if (num_msg > 5) {
  18499. + num_msg = 0;
  18500. + raw_spin_unlock_irq(&logbuf_lock);
  18501. + raw_spin_lock_irq(&logbuf_lock);
  18502. + if (clear_seq < log_first_seq)
  18503. + goto try_again;
  18504. + }
  18505. }
  18506. /* last message fitting into this dump */
  18507. @@ -1288,6 +1371,7 @@
  18508. clear_seq = log_next_seq;
  18509. clear_idx = log_next_idx;
  18510. }
  18511. +out:
  18512. raw_spin_unlock_irq(&logbuf_lock);
  18513. kfree(text);
  18514. @@ -1443,6 +1527,12 @@
  18515. if (!console_drivers)
  18516. return;
  18517. + if (IS_ENABLED(CONFIG_PREEMPT_RT_BASE)) {
  18518. + if (in_irq() || in_nmi())
  18519. + return;
  18520. + }
  18521. +
  18522. + migrate_disable();
  18523. for_each_console(con) {
  18524. if (exclusive_console && con != exclusive_console)
  18525. continue;
  18526. @@ -1458,6 +1548,7 @@
  18527. else
  18528. con->write(con, text, len);
  18529. }
  18530. + migrate_enable();
  18531. }
  18532. /*
  18533. @@ -1518,6 +1609,15 @@
  18534. static int console_trylock_for_printk(void)
  18535. {
  18536. unsigned int cpu = smp_processor_id();
  18537. +#ifdef CONFIG_PREEMPT_RT_FULL
  18538. + int lock = !early_boot_irqs_disabled && (preempt_count() == 0) &&
  18539. + !irqs_disabled();
  18540. +#else
  18541. + int lock = 1;
  18542. +#endif
  18543. +
  18544. + if (!lock)
  18545. + return 0;
  18546. if (!console_trylock())
  18547. return 0;
  18548. @@ -1672,6 +1772,13 @@
  18549. /* cpu currently holding logbuf_lock in this function */
  18550. static unsigned int logbuf_cpu = UINT_MAX;
  18551. + /*
  18552. + * Fall back to early_printk if a debugging subsystem has
  18553. + * killed printk output
  18554. + */
  18555. + if (unlikely(forced_early_printk(fmt, args)))
  18556. + return 1;
  18557. +
  18558. if (level == LOGLEVEL_SCHED) {
  18559. level = LOGLEVEL_DEFAULT;
  18560. in_sched = true;
  18561. @@ -1813,8 +1920,7 @@
  18562. * console_sem which would prevent anyone from printing to
  18563. * console
  18564. */
  18565. - preempt_disable();
  18566. -
  18567. + migrate_disable();
  18568. /*
  18569. * Try to acquire and then immediately release the console
  18570. * semaphore. The release will print out buffers and wake up
  18571. @@ -1822,7 +1928,7 @@
  18572. */
  18573. if (console_trylock_for_printk())
  18574. console_unlock();
  18575. - preempt_enable();
  18576. + migrate_enable();
  18577. lockdep_on();
  18578. }
  18579. @@ -1961,26 +2067,6 @@
  18580. #endif /* CONFIG_PRINTK */
  18581. -#ifdef CONFIG_EARLY_PRINTK
  18582. -struct console *early_console;
  18583. -
  18584. -asmlinkage __visible void early_printk(const char *fmt, ...)
  18585. -{
  18586. - va_list ap;
  18587. - char buf[512];
  18588. - int n;
  18589. -
  18590. - if (!early_console)
  18591. - return;
  18592. -
  18593. - va_start(ap, fmt);
  18594. - n = vscnprintf(buf, sizeof(buf), fmt, ap);
  18595. - va_end(ap);
  18596. -
  18597. - early_console->write(early_console, buf, n);
  18598. -}
  18599. -#endif
  18600. -
  18601. static int __add_preferred_console(char *name, int idx, char *options,
  18602. char *brl_options)
  18603. {
  18604. @@ -2202,11 +2288,16 @@
  18605. goto out;
  18606. len = cont_print_text(text, size);
  18607. +#ifdef CONFIG_PREEMPT_RT_FULL
  18608. + raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  18609. + call_console_drivers(cont.level, NULL, 0, text, len);
  18610. +#else
  18611. raw_spin_unlock(&logbuf_lock);
  18612. stop_critical_timings();
  18613. call_console_drivers(cont.level, NULL, 0, text, len);
  18614. start_critical_timings();
  18615. local_irq_restore(flags);
  18616. +#endif
  18617. return;
  18618. out:
  18619. raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  18620. @@ -2316,13 +2407,17 @@
  18621. console_idx = log_next(console_idx);
  18622. console_seq++;
  18623. console_prev = msg->flags;
  18624. +#ifdef CONFIG_PREEMPT_RT_FULL
  18625. + raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  18626. + call_console_drivers(level, ext_text, ext_len, text, len);
  18627. +#else
  18628. raw_spin_unlock(&logbuf_lock);
  18629. stop_critical_timings(); /* don't trace print latency */
  18630. call_console_drivers(level, ext_text, ext_len, text, len);
  18631. start_critical_timings();
  18632. local_irq_restore(flags);
  18633. -
  18634. +#endif
  18635. if (do_cond_resched)
  18636. cond_resched();
  18637. }
  18638. @@ -2374,6 +2469,11 @@
  18639. {
  18640. struct console *c;
  18641. + if (IS_ENABLED(CONFIG_PREEMPT_RT_BASE)) {
  18642. + if (in_irq() || in_nmi())
  18643. + return;
  18644. + }
  18645. +
  18646. /*
  18647. * console_unblank can no longer be called in interrupt context unless
  18648. * oops_in_progress is set to 1..
  18649. diff -Nur linux-4.4.13.orig/kernel/ptrace.c linux-4.4.13/kernel/ptrace.c
  18650. --- linux-4.4.13.orig/kernel/ptrace.c 2016-06-08 03:14:51.000000000 +0200
  18651. +++ linux-4.4.13/kernel/ptrace.c 2016-06-22 21:55:08.054523867 +0200
  18652. @@ -129,7 +129,14 @@
  18653. spin_lock_irq(&task->sighand->siglock);
  18654. if (task_is_traced(task) && !__fatal_signal_pending(task)) {
  18655. - task->state = __TASK_TRACED;
  18656. + unsigned long flags;
  18657. +
  18658. + raw_spin_lock_irqsave(&task->pi_lock, flags);
  18659. + if (task->state & __TASK_TRACED)
  18660. + task->state = __TASK_TRACED;
  18661. + else
  18662. + task->saved_state = __TASK_TRACED;
  18663. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  18664. ret = true;
  18665. }
  18666. spin_unlock_irq(&task->sighand->siglock);
  18667. diff -Nur linux-4.4.13.orig/kernel/rcu/rcutorture.c linux-4.4.13/kernel/rcu/rcutorture.c
  18668. --- linux-4.4.13.orig/kernel/rcu/rcutorture.c 2016-06-08 03:14:51.000000000 +0200
  18669. +++ linux-4.4.13/kernel/rcu/rcutorture.c 2016-06-22 21:55:08.054523867 +0200
  18670. @@ -390,6 +390,7 @@
  18671. .name = "rcu"
  18672. };
  18673. +#ifndef CONFIG_PREEMPT_RT_FULL
  18674. /*
  18675. * Definitions for rcu_bh torture testing.
  18676. */
  18677. @@ -429,6 +430,12 @@
  18678. .name = "rcu_bh"
  18679. };
  18680. +#else
  18681. +static struct rcu_torture_ops rcu_bh_ops = {
  18682. + .ttype = INVALID_RCU_FLAVOR,
  18683. +};
  18684. +#endif
  18685. +
  18686. /*
  18687. * Don't even think about trying any of these in real life!!!
  18688. * The names includes "busted", and they really means it!
  18689. diff -Nur linux-4.4.13.orig/kernel/rcu/tree.c linux-4.4.13/kernel/rcu/tree.c
  18690. --- linux-4.4.13.orig/kernel/rcu/tree.c 2016-06-08 03:14:51.000000000 +0200
  18691. +++ linux-4.4.13/kernel/rcu/tree.c 2016-06-22 21:55:08.054523867 +0200
  18692. @@ -56,6 +56,11 @@
  18693. #include <linux/random.h>
  18694. #include <linux/trace_events.h>
  18695. #include <linux/suspend.h>
  18696. +#include <linux/delay.h>
  18697. +#include <linux/gfp.h>
  18698. +#include <linux/oom.h>
  18699. +#include <linux/smpboot.h>
  18700. +#include "../time/tick-internal.h"
  18701. #include "tree.h"
  18702. #include "rcu.h"
  18703. @@ -266,6 +271,19 @@
  18704. }
  18705. }
  18706. +#ifdef CONFIG_PREEMPT_RT_FULL
  18707. +static void rcu_preempt_qs(void);
  18708. +
  18709. +void rcu_bh_qs(void)
  18710. +{
  18711. + unsigned long flags;
  18712. +
  18713. + /* Callers to this function, rcu_preempt_qs(), must disable irqs. */
  18714. + local_irq_save(flags);
  18715. + rcu_preempt_qs();
  18716. + local_irq_restore(flags);
  18717. +}
  18718. +#else
  18719. void rcu_bh_qs(void)
  18720. {
  18721. if (__this_cpu_read(rcu_bh_data.cpu_no_qs.s)) {
  18722. @@ -275,6 +293,7 @@
  18723. __this_cpu_write(rcu_bh_data.cpu_no_qs.b.norm, false);
  18724. }
  18725. }
  18726. +#endif
  18727. static DEFINE_PER_CPU(int, rcu_sched_qs_mask);
  18728. @@ -435,11 +454,13 @@
  18729. /*
  18730. * Return the number of RCU BH batches started thus far for debug & stats.
  18731. */
  18732. +#ifndef CONFIG_PREEMPT_RT_FULL
  18733. unsigned long rcu_batches_started_bh(void)
  18734. {
  18735. return rcu_bh_state.gpnum;
  18736. }
  18737. EXPORT_SYMBOL_GPL(rcu_batches_started_bh);
  18738. +#endif
  18739. /*
  18740. * Return the number of RCU batches completed thus far for debug & stats.
  18741. @@ -459,6 +480,7 @@
  18742. }
  18743. EXPORT_SYMBOL_GPL(rcu_batches_completed_sched);
  18744. +#ifndef CONFIG_PREEMPT_RT_FULL
  18745. /*
  18746. * Return the number of RCU BH batches completed thus far for debug & stats.
  18747. */
  18748. @@ -486,6 +508,13 @@
  18749. }
  18750. EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state);
  18751. +#else
  18752. +void rcu_force_quiescent_state(void)
  18753. +{
  18754. +}
  18755. +EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
  18756. +#endif
  18757. +
  18758. /*
  18759. * Force a quiescent state for RCU-sched.
  18760. */
  18761. @@ -536,9 +565,11 @@
  18762. case RCU_FLAVOR:
  18763. rsp = rcu_state_p;
  18764. break;
  18765. +#ifndef CONFIG_PREEMPT_RT_FULL
  18766. case RCU_BH_FLAVOR:
  18767. rsp = &rcu_bh_state;
  18768. break;
  18769. +#endif
  18770. case RCU_SCHED_FLAVOR:
  18771. rsp = &rcu_sched_state;
  18772. break;
  18773. @@ -1590,7 +1621,6 @@
  18774. int needmore;
  18775. struct rcu_data *rdp = this_cpu_ptr(rsp->rda);
  18776. - rcu_nocb_gp_cleanup(rsp, rnp);
  18777. rnp->need_future_gp[c & 0x1] = 0;
  18778. needmore = rnp->need_future_gp[(c + 1) & 0x1];
  18779. trace_rcu_future_gp(rnp, rdp, c,
  18780. @@ -1611,7 +1641,7 @@
  18781. !READ_ONCE(rsp->gp_flags) ||
  18782. !rsp->gp_kthread)
  18783. return;
  18784. - wake_up(&rsp->gp_wq);
  18785. + swake_up(&rsp->gp_wq);
  18786. }
  18787. /*
  18788. @@ -1991,6 +2021,7 @@
  18789. int nocb = 0;
  18790. struct rcu_data *rdp;
  18791. struct rcu_node *rnp = rcu_get_root(rsp);
  18792. + struct swait_queue_head *sq;
  18793. WRITE_ONCE(rsp->gp_activity, jiffies);
  18794. raw_spin_lock_irq(&rnp->lock);
  18795. @@ -2029,7 +2060,9 @@
  18796. needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
  18797. /* smp_mb() provided by prior unlock-lock pair. */
  18798. nocb += rcu_future_gp_cleanup(rsp, rnp);
  18799. + sq = rcu_nocb_gp_get(rnp);
  18800. raw_spin_unlock_irq(&rnp->lock);
  18801. + rcu_nocb_gp_cleanup(sq);
  18802. cond_resched_rcu_qs();
  18803. WRITE_ONCE(rsp->gp_activity, jiffies);
  18804. rcu_gp_slow(rsp, gp_cleanup_delay);
  18805. @@ -2076,7 +2109,7 @@
  18806. READ_ONCE(rsp->gpnum),
  18807. TPS("reqwait"));
  18808. rsp->gp_state = RCU_GP_WAIT_GPS;
  18809. - wait_event_interruptible(rsp->gp_wq,
  18810. + swait_event_interruptible(rsp->gp_wq,
  18811. READ_ONCE(rsp->gp_flags) &
  18812. RCU_GP_FLAG_INIT);
  18813. rsp->gp_state = RCU_GP_DONE_GPS;
  18814. @@ -2106,7 +2139,7 @@
  18815. READ_ONCE(rsp->gpnum),
  18816. TPS("fqswait"));
  18817. rsp->gp_state = RCU_GP_WAIT_FQS;
  18818. - ret = wait_event_interruptible_timeout(rsp->gp_wq,
  18819. + ret = swait_event_interruptible_timeout(rsp->gp_wq,
  18820. rcu_gp_fqs_check_wake(rsp, &gf), j);
  18821. rsp->gp_state = RCU_GP_DOING_FQS;
  18822. /* Locking provides needed memory barriers. */
  18823. @@ -2230,7 +2263,7 @@
  18824. WARN_ON_ONCE(!rcu_gp_in_progress(rsp));
  18825. WRITE_ONCE(rsp->gp_flags, READ_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS);
  18826. raw_spin_unlock_irqrestore(&rcu_get_root(rsp)->lock, flags);
  18827. - rcu_gp_kthread_wake(rsp);
  18828. + swake_up(&rsp->gp_wq); /* Memory barrier implied by swake_up() path. */
  18829. }
  18830. /*
  18831. @@ -2891,7 +2924,7 @@
  18832. }
  18833. WRITE_ONCE(rsp->gp_flags, READ_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS);
  18834. raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
  18835. - rcu_gp_kthread_wake(rsp);
  18836. + swake_up(&rsp->gp_wq); /* Memory barrier implied by swake_up() path. */
  18837. }
  18838. /*
  18839. @@ -2934,18 +2967,17 @@
  18840. /*
  18841. * Do RCU core processing for the current CPU.
  18842. */
  18843. -static void rcu_process_callbacks(struct softirq_action *unused)
  18844. +static void rcu_process_callbacks(void)
  18845. {
  18846. struct rcu_state *rsp;
  18847. if (cpu_is_offline(smp_processor_id()))
  18848. return;
  18849. - trace_rcu_utilization(TPS("Start RCU core"));
  18850. for_each_rcu_flavor(rsp)
  18851. __rcu_process_callbacks(rsp);
  18852. - trace_rcu_utilization(TPS("End RCU core"));
  18853. }
  18854. +static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
  18855. /*
  18856. * Schedule RCU callback invocation. If the specified type of RCU
  18857. * does not support RCU priority boosting, just do a direct call,
  18858. @@ -2957,18 +2989,105 @@
  18859. {
  18860. if (unlikely(!READ_ONCE(rcu_scheduler_fully_active)))
  18861. return;
  18862. - if (likely(!rsp->boost)) {
  18863. - rcu_do_batch(rsp, rdp);
  18864. + rcu_do_batch(rsp, rdp);
  18865. +}
  18866. +
  18867. +static void rcu_wake_cond(struct task_struct *t, int status)
  18868. +{
  18869. + /*
  18870. + * If the thread is yielding, only wake it when this
  18871. + * is invoked from idle
  18872. + */
  18873. + if (t && (status != RCU_KTHREAD_YIELDING || is_idle_task(current)))
  18874. + wake_up_process(t);
  18875. +}
  18876. +
  18877. +/*
  18878. + * Wake up this CPU's rcuc kthread to do RCU core processing.
  18879. + */
  18880. +static void invoke_rcu_core(void)
  18881. +{
  18882. + unsigned long flags;
  18883. + struct task_struct *t;
  18884. +
  18885. + if (!cpu_online(smp_processor_id()))
  18886. return;
  18887. + local_irq_save(flags);
  18888. + __this_cpu_write(rcu_cpu_has_work, 1);
  18889. + t = __this_cpu_read(rcu_cpu_kthread_task);
  18890. + if (t != NULL && current != t)
  18891. + rcu_wake_cond(t, __this_cpu_read(rcu_cpu_kthread_status));
  18892. + local_irq_restore(flags);
  18893. +}
  18894. +
  18895. +static void rcu_cpu_kthread_park(unsigned int cpu)
  18896. +{
  18897. + per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
  18898. +}
  18899. +
  18900. +static int rcu_cpu_kthread_should_run(unsigned int cpu)
  18901. +{
  18902. + return __this_cpu_read(rcu_cpu_has_work);
  18903. +}
  18904. +
  18905. +/*
  18906. + * Per-CPU kernel thread that invokes RCU callbacks. This replaces the
  18907. + * RCU softirq used in flavors and configurations of RCU that do not
  18908. + * support RCU priority boosting.
  18909. + */
  18910. +static void rcu_cpu_kthread(unsigned int cpu)
  18911. +{
  18912. + unsigned int *statusp = this_cpu_ptr(&rcu_cpu_kthread_status);
  18913. + char work, *workp = this_cpu_ptr(&rcu_cpu_has_work);
  18914. + int spincnt;
  18915. +
  18916. + for (spincnt = 0; spincnt < 10; spincnt++) {
  18917. + trace_rcu_utilization(TPS("Start CPU kthread@rcu_wait"));
  18918. + local_bh_disable();
  18919. + *statusp = RCU_KTHREAD_RUNNING;
  18920. + this_cpu_inc(rcu_cpu_kthread_loops);
  18921. + local_irq_disable();
  18922. + work = *workp;
  18923. + *workp = 0;
  18924. + local_irq_enable();
  18925. + if (work)
  18926. + rcu_process_callbacks();
  18927. + local_bh_enable();
  18928. + if (*workp == 0) {
  18929. + trace_rcu_utilization(TPS("End CPU kthread@rcu_wait"));
  18930. + *statusp = RCU_KTHREAD_WAITING;
  18931. + return;
  18932. + }
  18933. }
  18934. - invoke_rcu_callbacks_kthread();
  18935. + *statusp = RCU_KTHREAD_YIELDING;
  18936. + trace_rcu_utilization(TPS("Start CPU kthread@rcu_yield"));
  18937. + schedule_timeout_interruptible(2);
  18938. + trace_rcu_utilization(TPS("End CPU kthread@rcu_yield"));
  18939. + *statusp = RCU_KTHREAD_WAITING;
  18940. }
  18941. -static void invoke_rcu_core(void)
  18942. +static struct smp_hotplug_thread rcu_cpu_thread_spec = {
  18943. + .store = &rcu_cpu_kthread_task,
  18944. + .thread_should_run = rcu_cpu_kthread_should_run,
  18945. + .thread_fn = rcu_cpu_kthread,
  18946. + .thread_comm = "rcuc/%u",
  18947. + .setup = rcu_cpu_kthread_setup,
  18948. + .park = rcu_cpu_kthread_park,
  18949. +};
  18950. +
  18951. +/*
  18952. + * Spawn per-CPU RCU core processing kthreads.
  18953. + */
  18954. +static int __init rcu_spawn_core_kthreads(void)
  18955. {
  18956. - if (cpu_online(smp_processor_id()))
  18957. - raise_softirq(RCU_SOFTIRQ);
  18958. + int cpu;
  18959. +
  18960. + for_each_possible_cpu(cpu)
  18961. + per_cpu(rcu_cpu_has_work, cpu) = 0;
  18962. + BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec));
  18963. + return 0;
  18964. }
  18965. +early_initcall(rcu_spawn_core_kthreads);
  18966. /*
  18967. * Handle any core-RCU processing required by a call_rcu() invocation.
  18968. @@ -3114,6 +3233,7 @@
  18969. }
  18970. EXPORT_SYMBOL_GPL(call_rcu_sched);
  18971. +#ifndef CONFIG_PREEMPT_RT_FULL
  18972. /*
  18973. * Queue an RCU callback for invocation after a quicker grace period.
  18974. */
  18975. @@ -3122,6 +3242,7 @@
  18976. __call_rcu(head, func, &rcu_bh_state, -1, 0);
  18977. }
  18978. EXPORT_SYMBOL_GPL(call_rcu_bh);
  18979. +#endif
  18980. /*
  18981. * Queue an RCU callback for lazy invocation after a grace period.
  18982. @@ -3213,6 +3334,7 @@
  18983. }
  18984. EXPORT_SYMBOL_GPL(synchronize_sched);
  18985. +#ifndef CONFIG_PREEMPT_RT_FULL
  18986. /**
  18987. * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed.
  18988. *
  18989. @@ -3239,6 +3361,7 @@
  18990. wait_rcu_gp(call_rcu_bh);
  18991. }
  18992. EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
  18993. +#endif
  18994. /**
  18995. * get_state_synchronize_rcu - Snapshot current RCU state
  18996. @@ -3524,7 +3647,7 @@
  18997. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  18998. if (wake) {
  18999. smp_mb(); /* EGP done before wake_up(). */
  19000. - wake_up(&rsp->expedited_wq);
  19001. + swake_up(&rsp->expedited_wq);
  19002. }
  19003. break;
  19004. }
  19005. @@ -3781,7 +3904,7 @@
  19006. jiffies_start = jiffies;
  19007. for (;;) {
  19008. - ret = wait_event_interruptible_timeout(
  19009. + ret = swait_event_timeout(
  19010. rsp->expedited_wq,
  19011. sync_rcu_preempt_exp_done(rnp_root),
  19012. jiffies_stall);
  19013. @@ -3789,7 +3912,7 @@
  19014. return;
  19015. if (ret < 0) {
  19016. /* Hit a signal, disable CPU stall warnings. */
  19017. - wait_event(rsp->expedited_wq,
  19018. + swait_event(rsp->expedited_wq,
  19019. sync_rcu_preempt_exp_done(rnp_root));
  19020. return;
  19021. }
  19022. @@ -4101,6 +4224,7 @@
  19023. mutex_unlock(&rsp->barrier_mutex);
  19024. }
  19025. +#ifndef CONFIG_PREEMPT_RT_FULL
  19026. /**
  19027. * rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete.
  19028. */
  19029. @@ -4109,6 +4233,7 @@
  19030. _rcu_barrier(&rcu_bh_state);
  19031. }
  19032. EXPORT_SYMBOL_GPL(rcu_barrier_bh);
  19033. +#endif
  19034. /**
  19035. * rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks.
  19036. @@ -4455,8 +4580,8 @@
  19037. }
  19038. }
  19039. - init_waitqueue_head(&rsp->gp_wq);
  19040. - init_waitqueue_head(&rsp->expedited_wq);
  19041. + init_swait_queue_head(&rsp->gp_wq);
  19042. + init_swait_queue_head(&rsp->expedited_wq);
  19043. rnp = rsp->level[rcu_num_lvls - 1];
  19044. for_each_possible_cpu(i) {
  19045. while (i > rnp->grphi)
  19046. @@ -4576,12 +4701,13 @@
  19047. rcu_bootup_announce();
  19048. rcu_init_geometry();
  19049. +#ifndef CONFIG_PREEMPT_RT_FULL
  19050. rcu_init_one(&rcu_bh_state, &rcu_bh_data);
  19051. +#endif
  19052. rcu_init_one(&rcu_sched_state, &rcu_sched_data);
  19053. if (dump_tree)
  19054. rcu_dump_rcu_node_tree(&rcu_sched_state);
  19055. __rcu_init_preempt();
  19056. - open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
  19057. /*
  19058. * We don't need protection against CPU-hotplug here because
  19059. diff -Nur linux-4.4.13.orig/kernel/rcu/tree.h linux-4.4.13/kernel/rcu/tree.h
  19060. --- linux-4.4.13.orig/kernel/rcu/tree.h 2016-06-08 03:14:51.000000000 +0200
  19061. +++ linux-4.4.13/kernel/rcu/tree.h 2016-06-22 21:55:08.054523867 +0200
  19062. @@ -27,6 +27,7 @@
  19063. #include <linux/threads.h>
  19064. #include <linux/cpumask.h>
  19065. #include <linux/seqlock.h>
  19066. +#include <linux/swait.h>
  19067. #include <linux/stop_machine.h>
  19068. /*
  19069. @@ -241,7 +242,7 @@
  19070. /* Refused to boost: not sure why, though. */
  19071. /* This can happen due to race conditions. */
  19072. #ifdef CONFIG_RCU_NOCB_CPU
  19073. - wait_queue_head_t nocb_gp_wq[2];
  19074. + struct swait_queue_head nocb_gp_wq[2];
  19075. /* Place for rcu_nocb_kthread() to wait GP. */
  19076. #endif /* #ifdef CONFIG_RCU_NOCB_CPU */
  19077. int need_future_gp[2];
  19078. @@ -393,7 +394,7 @@
  19079. atomic_long_t nocb_q_count_lazy; /* invocation (all stages). */
  19080. struct rcu_head *nocb_follower_head; /* CBs ready to invoke. */
  19081. struct rcu_head **nocb_follower_tail;
  19082. - wait_queue_head_t nocb_wq; /* For nocb kthreads to sleep on. */
  19083. + struct swait_queue_head nocb_wq; /* For nocb kthreads to sleep on. */
  19084. struct task_struct *nocb_kthread;
  19085. int nocb_defer_wakeup; /* Defer wakeup of nocb_kthread. */
  19086. @@ -472,7 +473,7 @@
  19087. unsigned long gpnum; /* Current gp number. */
  19088. unsigned long completed; /* # of last completed gp. */
  19089. struct task_struct *gp_kthread; /* Task for grace periods. */
  19090. - wait_queue_head_t gp_wq; /* Where GP task waits. */
  19091. + struct swait_queue_head gp_wq; /* Where GP task waits. */
  19092. short gp_flags; /* Commands for GP task. */
  19093. short gp_state; /* GP kthread sleep state. */
  19094. @@ -504,7 +505,7 @@
  19095. atomic_long_t expedited_workdone3; /* # done by others #3. */
  19096. atomic_long_t expedited_normal; /* # fallbacks to normal. */
  19097. atomic_t expedited_need_qs; /* # CPUs left to check in. */
  19098. - wait_queue_head_t expedited_wq; /* Wait for check-ins. */
  19099. + struct swait_queue_head expedited_wq; /* Wait for check-ins. */
  19100. int ncpus_snap; /* # CPUs seen last time. */
  19101. unsigned long jiffies_force_qs; /* Time at which to invoke */
  19102. @@ -556,18 +557,18 @@
  19103. */
  19104. extern struct rcu_state rcu_sched_state;
  19105. +#ifndef CONFIG_PREEMPT_RT_FULL
  19106. extern struct rcu_state rcu_bh_state;
  19107. +#endif
  19108. #ifdef CONFIG_PREEMPT_RCU
  19109. extern struct rcu_state rcu_preempt_state;
  19110. #endif /* #ifdef CONFIG_PREEMPT_RCU */
  19111. -#ifdef CONFIG_RCU_BOOST
  19112. DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
  19113. DECLARE_PER_CPU(int, rcu_cpu_kthread_cpu);
  19114. DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
  19115. DECLARE_PER_CPU(char, rcu_cpu_has_work);
  19116. -#endif /* #ifdef CONFIG_RCU_BOOST */
  19117. #ifndef RCU_TREE_NONCORE
  19118. @@ -587,10 +588,9 @@
  19119. static void __init __rcu_init_preempt(void);
  19120. static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags);
  19121. static void rcu_preempt_boost_start_gp(struct rcu_node *rnp);
  19122. -static void invoke_rcu_callbacks_kthread(void);
  19123. static bool rcu_is_callbacks_kthread(void);
  19124. +static void rcu_cpu_kthread_setup(unsigned int cpu);
  19125. #ifdef CONFIG_RCU_BOOST
  19126. -static void rcu_preempt_do_callbacks(void);
  19127. static int rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
  19128. struct rcu_node *rnp);
  19129. #endif /* #ifdef CONFIG_RCU_BOOST */
  19130. @@ -607,7 +607,8 @@
  19131. static void increment_cpu_stall_ticks(void);
  19132. static bool rcu_nocb_cpu_needs_barrier(struct rcu_state *rsp, int cpu);
  19133. static void rcu_nocb_gp_set(struct rcu_node *rnp, int nrq);
  19134. -static void rcu_nocb_gp_cleanup(struct rcu_state *rsp, struct rcu_node *rnp);
  19135. +static struct swait_queue_head *rcu_nocb_gp_get(struct rcu_node *rnp);
  19136. +static void rcu_nocb_gp_cleanup(struct swait_queue_head *sq);
  19137. static void rcu_init_one_nocb(struct rcu_node *rnp);
  19138. static bool __call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *rhp,
  19139. bool lazy, unsigned long flags);
  19140. diff -Nur linux-4.4.13.orig/kernel/rcu/tree_plugin.h linux-4.4.13/kernel/rcu/tree_plugin.h
  19141. --- linux-4.4.13.orig/kernel/rcu/tree_plugin.h 2016-06-08 03:14:51.000000000 +0200
  19142. +++ linux-4.4.13/kernel/rcu/tree_plugin.h 2016-06-22 21:55:08.054523867 +0200
  19143. @@ -24,25 +24,10 @@
  19144. * Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  19145. */
  19146. -#include <linux/delay.h>
  19147. -#include <linux/gfp.h>
  19148. -#include <linux/oom.h>
  19149. -#include <linux/smpboot.h>
  19150. -#include "../time/tick-internal.h"
  19151. -
  19152. #ifdef CONFIG_RCU_BOOST
  19153. #include "../locking/rtmutex_common.h"
  19154. -/*
  19155. - * Control variables for per-CPU and per-rcu_node kthreads. These
  19156. - * handle all flavors of RCU.
  19157. - */
  19158. -static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
  19159. -DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
  19160. -DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
  19161. -DEFINE_PER_CPU(char, rcu_cpu_has_work);
  19162. -
  19163. #else /* #ifdef CONFIG_RCU_BOOST */
  19164. /*
  19165. @@ -55,6 +40,14 @@
  19166. #endif /* #else #ifdef CONFIG_RCU_BOOST */
  19167. +/*
  19168. + * Control variables for per-CPU and per-rcu_node kthreads. These
  19169. + * handle all flavors of RCU.
  19170. + */
  19171. +DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
  19172. +DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
  19173. +DEFINE_PER_CPU(char, rcu_cpu_has_work);
  19174. +
  19175. #ifdef CONFIG_RCU_NOCB_CPU
  19176. static cpumask_var_t rcu_nocb_mask; /* CPUs to have callbacks offloaded. */
  19177. static bool have_rcu_nocb_mask; /* Was rcu_nocb_mask allocated? */
  19178. @@ -432,7 +425,7 @@
  19179. }
  19180. /* Hardware IRQ handlers cannot block, complain if they get here. */
  19181. - if (in_irq() || in_serving_softirq()) {
  19182. + if (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_OFFSET)) {
  19183. lockdep_rcu_suspicious(__FILE__, __LINE__,
  19184. "rcu_read_unlock() from irq or softirq with blocking in critical section!!!\n");
  19185. pr_alert("->rcu_read_unlock_special: %#x (b: %d, enq: %d nq: %d)\n",
  19186. @@ -645,15 +638,6 @@
  19187. t->rcu_read_unlock_special.b.need_qs = true;
  19188. }
  19189. -#ifdef CONFIG_RCU_BOOST
  19190. -
  19191. -static void rcu_preempt_do_callbacks(void)
  19192. -{
  19193. - rcu_do_batch(rcu_state_p, this_cpu_ptr(rcu_data_p));
  19194. -}
  19195. -
  19196. -#endif /* #ifdef CONFIG_RCU_BOOST */
  19197. -
  19198. /*
  19199. * Queue a preemptible-RCU callback for invocation after a grace period.
  19200. */
  19201. @@ -930,6 +914,19 @@
  19202. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  19203. +/*
  19204. + * If boosting, set rcuc kthreads to realtime priority.
  19205. + */
  19206. +static void rcu_cpu_kthread_setup(unsigned int cpu)
  19207. +{
  19208. +#ifdef CONFIG_RCU_BOOST
  19209. + struct sched_param sp;
  19210. +
  19211. + sp.sched_priority = kthread_prio;
  19212. + sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
  19213. +#endif /* #ifdef CONFIG_RCU_BOOST */
  19214. +}
  19215. +
  19216. #ifdef CONFIG_RCU_BOOST
  19217. #include "../locking/rtmutex_common.h"
  19218. @@ -961,16 +958,6 @@
  19219. #endif /* #else #ifdef CONFIG_RCU_TRACE */
  19220. -static void rcu_wake_cond(struct task_struct *t, int status)
  19221. -{
  19222. - /*
  19223. - * If the thread is yielding, only wake it when this
  19224. - * is invoked from idle
  19225. - */
  19226. - if (status != RCU_KTHREAD_YIELDING || is_idle_task(current))
  19227. - wake_up_process(t);
  19228. -}
  19229. -
  19230. /*
  19231. * Carry out RCU priority boosting on the task indicated by ->exp_tasks
  19232. * or ->boost_tasks, advancing the pointer to the next task in the
  19233. @@ -1115,23 +1102,6 @@
  19234. }
  19235. /*
  19236. - * Wake up the per-CPU kthread to invoke RCU callbacks.
  19237. - */
  19238. -static void invoke_rcu_callbacks_kthread(void)
  19239. -{
  19240. - unsigned long flags;
  19241. -
  19242. - local_irq_save(flags);
  19243. - __this_cpu_write(rcu_cpu_has_work, 1);
  19244. - if (__this_cpu_read(rcu_cpu_kthread_task) != NULL &&
  19245. - current != __this_cpu_read(rcu_cpu_kthread_task)) {
  19246. - rcu_wake_cond(__this_cpu_read(rcu_cpu_kthread_task),
  19247. - __this_cpu_read(rcu_cpu_kthread_status));
  19248. - }
  19249. - local_irq_restore(flags);
  19250. -}
  19251. -
  19252. -/*
  19253. * Is the current CPU running the RCU-callbacks kthread?
  19254. * Caller must have preemption disabled.
  19255. */
  19256. @@ -1186,67 +1156,6 @@
  19257. return 0;
  19258. }
  19259. -static void rcu_kthread_do_work(void)
  19260. -{
  19261. - rcu_do_batch(&rcu_sched_state, this_cpu_ptr(&rcu_sched_data));
  19262. - rcu_do_batch(&rcu_bh_state, this_cpu_ptr(&rcu_bh_data));
  19263. - rcu_preempt_do_callbacks();
  19264. -}
  19265. -
  19266. -static void rcu_cpu_kthread_setup(unsigned int cpu)
  19267. -{
  19268. - struct sched_param sp;
  19269. -
  19270. - sp.sched_priority = kthread_prio;
  19271. - sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
  19272. -}
  19273. -
  19274. -static void rcu_cpu_kthread_park(unsigned int cpu)
  19275. -{
  19276. - per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
  19277. -}
  19278. -
  19279. -static int rcu_cpu_kthread_should_run(unsigned int cpu)
  19280. -{
  19281. - return __this_cpu_read(rcu_cpu_has_work);
  19282. -}
  19283. -
  19284. -/*
  19285. - * Per-CPU kernel thread that invokes RCU callbacks. This replaces the
  19286. - * RCU softirq used in flavors and configurations of RCU that do not
  19287. - * support RCU priority boosting.
  19288. - */
  19289. -static void rcu_cpu_kthread(unsigned int cpu)
  19290. -{
  19291. - unsigned int *statusp = this_cpu_ptr(&rcu_cpu_kthread_status);
  19292. - char work, *workp = this_cpu_ptr(&rcu_cpu_has_work);
  19293. - int spincnt;
  19294. -
  19295. - for (spincnt = 0; spincnt < 10; spincnt++) {
  19296. - trace_rcu_utilization(TPS("Start CPU kthread@rcu_wait"));
  19297. - local_bh_disable();
  19298. - *statusp = RCU_KTHREAD_RUNNING;
  19299. - this_cpu_inc(rcu_cpu_kthread_loops);
  19300. - local_irq_disable();
  19301. - work = *workp;
  19302. - *workp = 0;
  19303. - local_irq_enable();
  19304. - if (work)
  19305. - rcu_kthread_do_work();
  19306. - local_bh_enable();
  19307. - if (*workp == 0) {
  19308. - trace_rcu_utilization(TPS("End CPU kthread@rcu_wait"));
  19309. - *statusp = RCU_KTHREAD_WAITING;
  19310. - return;
  19311. - }
  19312. - }
  19313. - *statusp = RCU_KTHREAD_YIELDING;
  19314. - trace_rcu_utilization(TPS("Start CPU kthread@rcu_yield"));
  19315. - schedule_timeout_interruptible(2);
  19316. - trace_rcu_utilization(TPS("End CPU kthread@rcu_yield"));
  19317. - *statusp = RCU_KTHREAD_WAITING;
  19318. -}
  19319. -
  19320. /*
  19321. * Set the per-rcu_node kthread's affinity to cover all CPUs that are
  19322. * served by the rcu_node in question. The CPU hotplug lock is still
  19323. @@ -1276,26 +1185,12 @@
  19324. free_cpumask_var(cm);
  19325. }
  19326. -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
  19327. - .store = &rcu_cpu_kthread_task,
  19328. - .thread_should_run = rcu_cpu_kthread_should_run,
  19329. - .thread_fn = rcu_cpu_kthread,
  19330. - .thread_comm = "rcuc/%u",
  19331. - .setup = rcu_cpu_kthread_setup,
  19332. - .park = rcu_cpu_kthread_park,
  19333. -};
  19334. -
  19335. /*
  19336. * Spawn boost kthreads -- called as soon as the scheduler is running.
  19337. */
  19338. static void __init rcu_spawn_boost_kthreads(void)
  19339. {
  19340. struct rcu_node *rnp;
  19341. - int cpu;
  19342. -
  19343. - for_each_possible_cpu(cpu)
  19344. - per_cpu(rcu_cpu_has_work, cpu) = 0;
  19345. - BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec));
  19346. rcu_for_each_leaf_node(rcu_state_p, rnp)
  19347. (void)rcu_spawn_one_boost_kthread(rcu_state_p, rnp);
  19348. }
  19349. @@ -1318,11 +1213,6 @@
  19350. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  19351. }
  19352. -static void invoke_rcu_callbacks_kthread(void)
  19353. -{
  19354. - WARN_ON_ONCE(1);
  19355. -}
  19356. -
  19357. static bool rcu_is_callbacks_kthread(void)
  19358. {
  19359. return false;
  19360. @@ -1346,7 +1236,7 @@
  19361. #endif /* #else #ifdef CONFIG_RCU_BOOST */
  19362. -#if !defined(CONFIG_RCU_FAST_NO_HZ)
  19363. +#if !defined(CONFIG_RCU_FAST_NO_HZ) || defined(CONFIG_PREEMPT_RT_FULL)
  19364. /*
  19365. * Check to see if any future RCU-related work will need to be done
  19366. @@ -1363,7 +1253,9 @@
  19367. return IS_ENABLED(CONFIG_RCU_NOCB_CPU_ALL)
  19368. ? 0 : rcu_cpu_has_callbacks(NULL);
  19369. }
  19370. +#endif /* !defined(CONFIG_RCU_FAST_NO_HZ) || defined(CONFIG_PREEMPT_RT_FULL) */
  19371. +#if !defined(CONFIG_RCU_FAST_NO_HZ)
  19372. /*
  19373. * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up
  19374. * after it.
  19375. @@ -1459,6 +1351,8 @@
  19376. return cbs_ready;
  19377. }
  19378. +#ifndef CONFIG_PREEMPT_RT_FULL
  19379. +
  19380. /*
  19381. * Allow the CPU to enter dyntick-idle mode unless it has callbacks ready
  19382. * to invoke. If the CPU has callbacks, try to advance them. Tell the
  19383. @@ -1504,6 +1398,7 @@
  19384. *nextevt = basemono + dj * TICK_NSEC;
  19385. return 0;
  19386. }
  19387. +#endif /* #ifndef CONFIG_PREEMPT_RT_FULL */
  19388. /*
  19389. * Prepare a CPU for idle from an RCU perspective. The first major task
  19390. @@ -1822,9 +1717,9 @@
  19391. * Wake up any no-CBs CPUs' kthreads that were waiting on the just-ended
  19392. * grace period.
  19393. */
  19394. -static void rcu_nocb_gp_cleanup(struct rcu_state *rsp, struct rcu_node *rnp)
  19395. +static void rcu_nocb_gp_cleanup(struct swait_queue_head *sq)
  19396. {
  19397. - wake_up_all(&rnp->nocb_gp_wq[rnp->completed & 0x1]);
  19398. + swake_up_all(sq);
  19399. }
  19400. /*
  19401. @@ -1840,10 +1735,15 @@
  19402. rnp->need_future_gp[(rnp->completed + 1) & 0x1] += nrq;
  19403. }
  19404. +static struct swait_queue_head *rcu_nocb_gp_get(struct rcu_node *rnp)
  19405. +{
  19406. + return &rnp->nocb_gp_wq[rnp->completed & 0x1];
  19407. +}
  19408. +
  19409. static void rcu_init_one_nocb(struct rcu_node *rnp)
  19410. {
  19411. - init_waitqueue_head(&rnp->nocb_gp_wq[0]);
  19412. - init_waitqueue_head(&rnp->nocb_gp_wq[1]);
  19413. + init_swait_queue_head(&rnp->nocb_gp_wq[0]);
  19414. + init_swait_queue_head(&rnp->nocb_gp_wq[1]);
  19415. }
  19416. #ifndef CONFIG_RCU_NOCB_CPU_ALL
  19417. @@ -1868,7 +1768,7 @@
  19418. if (READ_ONCE(rdp_leader->nocb_leader_sleep) || force) {
  19419. /* Prior smp_mb__after_atomic() orders against prior enqueue. */
  19420. WRITE_ONCE(rdp_leader->nocb_leader_sleep, false);
  19421. - wake_up(&rdp_leader->nocb_wq);
  19422. + swake_up(&rdp_leader->nocb_wq);
  19423. }
  19424. }
  19425. @@ -2081,7 +1981,7 @@
  19426. */
  19427. trace_rcu_future_gp(rnp, rdp, c, TPS("StartWait"));
  19428. for (;;) {
  19429. - wait_event_interruptible(
  19430. + swait_event_interruptible(
  19431. rnp->nocb_gp_wq[c & 0x1],
  19432. (d = ULONG_CMP_GE(READ_ONCE(rnp->completed), c)));
  19433. if (likely(d))
  19434. @@ -2109,7 +2009,7 @@
  19435. /* Wait for callbacks to appear. */
  19436. if (!rcu_nocb_poll) {
  19437. trace_rcu_nocb_wake(my_rdp->rsp->name, my_rdp->cpu, "Sleep");
  19438. - wait_event_interruptible(my_rdp->nocb_wq,
  19439. + swait_event_interruptible(my_rdp->nocb_wq,
  19440. !READ_ONCE(my_rdp->nocb_leader_sleep));
  19441. /* Memory barrier handled by smp_mb() calls below and repoll. */
  19442. } else if (firsttime) {
  19443. @@ -2184,7 +2084,7 @@
  19444. * List was empty, wake up the follower.
  19445. * Memory barriers supplied by atomic_long_add().
  19446. */
  19447. - wake_up(&rdp->nocb_wq);
  19448. + swake_up(&rdp->nocb_wq);
  19449. }
  19450. }
  19451. @@ -2205,7 +2105,7 @@
  19452. if (!rcu_nocb_poll) {
  19453. trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
  19454. "FollowerSleep");
  19455. - wait_event_interruptible(rdp->nocb_wq,
  19456. + swait_event_interruptible(rdp->nocb_wq,
  19457. READ_ONCE(rdp->nocb_follower_head));
  19458. } else if (firsttime) {
  19459. /* Don't drown trace log with "Poll"! */
  19460. @@ -2364,7 +2264,7 @@
  19461. static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp)
  19462. {
  19463. rdp->nocb_tail = &rdp->nocb_head;
  19464. - init_waitqueue_head(&rdp->nocb_wq);
  19465. + init_swait_queue_head(&rdp->nocb_wq);
  19466. rdp->nocb_follower_tail = &rdp->nocb_follower_head;
  19467. }
  19468. @@ -2514,7 +2414,7 @@
  19469. return false;
  19470. }
  19471. -static void rcu_nocb_gp_cleanup(struct rcu_state *rsp, struct rcu_node *rnp)
  19472. +static void rcu_nocb_gp_cleanup(struct swait_queue_head *sq)
  19473. {
  19474. }
  19475. @@ -2522,6 +2422,11 @@
  19476. {
  19477. }
  19478. +static struct swait_queue_head *rcu_nocb_gp_get(struct rcu_node *rnp)
  19479. +{
  19480. + return NULL;
  19481. +}
  19482. +
  19483. static void rcu_init_one_nocb(struct rcu_node *rnp)
  19484. {
  19485. }
  19486. diff -Nur linux-4.4.13.orig/kernel/rcu/update.c linux-4.4.13/kernel/rcu/update.c
  19487. --- linux-4.4.13.orig/kernel/rcu/update.c 2016-06-08 03:14:51.000000000 +0200
  19488. +++ linux-4.4.13/kernel/rcu/update.c 2016-06-22 21:55:08.054523867 +0200
  19489. @@ -276,6 +276,7 @@
  19490. }
  19491. EXPORT_SYMBOL_GPL(rcu_read_lock_held);
  19492. +#ifndef CONFIG_PREEMPT_RT_FULL
  19493. /**
  19494. * rcu_read_lock_bh_held() - might we be in RCU-bh read-side critical section?
  19495. *
  19496. @@ -302,6 +303,7 @@
  19497. return in_softirq() || irqs_disabled();
  19498. }
  19499. EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held);
  19500. +#endif
  19501. #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  19502. diff -Nur linux-4.4.13.orig/kernel/relay.c linux-4.4.13/kernel/relay.c
  19503. --- linux-4.4.13.orig/kernel/relay.c 2016-06-08 03:14:51.000000000 +0200
  19504. +++ linux-4.4.13/kernel/relay.c 2016-06-22 21:55:08.058523867 +0200
  19505. @@ -336,6 +336,10 @@
  19506. {
  19507. struct rchan_buf *buf = (struct rchan_buf *)data;
  19508. wake_up_interruptible(&buf->read_wait);
  19509. + /*
  19510. + * Stupid polling for now:
  19511. + */
  19512. + mod_timer(&buf->timer, jiffies + 1);
  19513. }
  19514. /**
  19515. @@ -353,6 +357,7 @@
  19516. init_waitqueue_head(&buf->read_wait);
  19517. kref_init(&buf->kref);
  19518. setup_timer(&buf->timer, wakeup_readers, (unsigned long)buf);
  19519. + mod_timer(&buf->timer, jiffies + 1);
  19520. } else
  19521. del_timer_sync(&buf->timer);
  19522. @@ -736,15 +741,6 @@
  19523. else
  19524. buf->early_bytes += buf->chan->subbuf_size -
  19525. buf->padding[old_subbuf];
  19526. - smp_mb();
  19527. - if (waitqueue_active(&buf->read_wait))
  19528. - /*
  19529. - * Calling wake_up_interruptible() from here
  19530. - * will deadlock if we happen to be logging
  19531. - * from the scheduler (trying to re-grab
  19532. - * rq->lock), so defer it.
  19533. - */
  19534. - mod_timer(&buf->timer, jiffies + 1);
  19535. }
  19536. old = buf->data;
  19537. diff -Nur linux-4.4.13.orig/kernel/sched/completion.c linux-4.4.13/kernel/sched/completion.c
  19538. --- linux-4.4.13.orig/kernel/sched/completion.c 2016-06-08 03:14:51.000000000 +0200
  19539. +++ linux-4.4.13/kernel/sched/completion.c 2016-06-22 21:55:08.058523867 +0200
  19540. @@ -30,10 +30,10 @@
  19541. {
  19542. unsigned long flags;
  19543. - spin_lock_irqsave(&x->wait.lock, flags);
  19544. + raw_spin_lock_irqsave(&x->wait.lock, flags);
  19545. x->done++;
  19546. - __wake_up_locked(&x->wait, TASK_NORMAL, 1);
  19547. - spin_unlock_irqrestore(&x->wait.lock, flags);
  19548. + swake_up_locked(&x->wait);
  19549. + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
  19550. }
  19551. EXPORT_SYMBOL(complete);
  19552. @@ -50,10 +50,10 @@
  19553. {
  19554. unsigned long flags;
  19555. - spin_lock_irqsave(&x->wait.lock, flags);
  19556. + raw_spin_lock_irqsave(&x->wait.lock, flags);
  19557. x->done += UINT_MAX/2;
  19558. - __wake_up_locked(&x->wait, TASK_NORMAL, 0);
  19559. - spin_unlock_irqrestore(&x->wait.lock, flags);
  19560. + swake_up_all_locked(&x->wait);
  19561. + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
  19562. }
  19563. EXPORT_SYMBOL(complete_all);
  19564. @@ -62,20 +62,20 @@
  19565. long (*action)(long), long timeout, int state)
  19566. {
  19567. if (!x->done) {
  19568. - DECLARE_WAITQUEUE(wait, current);
  19569. + DECLARE_SWAITQUEUE(wait);
  19570. - __add_wait_queue_tail_exclusive(&x->wait, &wait);
  19571. + __prepare_to_swait(&x->wait, &wait);
  19572. do {
  19573. if (signal_pending_state(state, current)) {
  19574. timeout = -ERESTARTSYS;
  19575. break;
  19576. }
  19577. __set_current_state(state);
  19578. - spin_unlock_irq(&x->wait.lock);
  19579. + raw_spin_unlock_irq(&x->wait.lock);
  19580. timeout = action(timeout);
  19581. - spin_lock_irq(&x->wait.lock);
  19582. + raw_spin_lock_irq(&x->wait.lock);
  19583. } while (!x->done && timeout);
  19584. - __remove_wait_queue(&x->wait, &wait);
  19585. + __finish_swait(&x->wait, &wait);
  19586. if (!x->done)
  19587. return timeout;
  19588. }
  19589. @@ -89,9 +89,9 @@
  19590. {
  19591. might_sleep();
  19592. - spin_lock_irq(&x->wait.lock);
  19593. + raw_spin_lock_irq(&x->wait.lock);
  19594. timeout = do_wait_for_common(x, action, timeout, state);
  19595. - spin_unlock_irq(&x->wait.lock);
  19596. + raw_spin_unlock_irq(&x->wait.lock);
  19597. return timeout;
  19598. }
  19599. @@ -277,12 +277,12 @@
  19600. if (!READ_ONCE(x->done))
  19601. return 0;
  19602. - spin_lock_irqsave(&x->wait.lock, flags);
  19603. + raw_spin_lock_irqsave(&x->wait.lock, flags);
  19604. if (!x->done)
  19605. ret = 0;
  19606. else
  19607. x->done--;
  19608. - spin_unlock_irqrestore(&x->wait.lock, flags);
  19609. + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
  19610. return ret;
  19611. }
  19612. EXPORT_SYMBOL(try_wait_for_completion);
  19613. @@ -311,7 +311,7 @@
  19614. * after it's acquired the lock.
  19615. */
  19616. smp_rmb();
  19617. - spin_unlock_wait(&x->wait.lock);
  19618. + raw_spin_unlock_wait(&x->wait.lock);
  19619. return true;
  19620. }
  19621. EXPORT_SYMBOL(completion_done);
  19622. diff -Nur linux-4.4.13.orig/kernel/sched/core.c linux-4.4.13/kernel/sched/core.c
  19623. --- linux-4.4.13.orig/kernel/sched/core.c 2016-06-08 03:14:51.000000000 +0200
  19624. +++ linux-4.4.13/kernel/sched/core.c 2016-06-22 21:55:08.058523867 +0200
  19625. @@ -260,7 +260,11 @@
  19626. * Number of tasks to iterate in a single balance run.
  19627. * Limited because this is done with IRQs disabled.
  19628. */
  19629. +#ifndef CONFIG_PREEMPT_RT_FULL
  19630. const_debug unsigned int sysctl_sched_nr_migrate = 32;
  19631. +#else
  19632. +const_debug unsigned int sysctl_sched_nr_migrate = 8;
  19633. +#endif
  19634. /*
  19635. * period over which we average the RT time consumption, measured
  19636. @@ -438,6 +442,7 @@
  19637. hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  19638. rq->hrtick_timer.function = hrtick;
  19639. + rq->hrtick_timer.irqsafe = 1;
  19640. }
  19641. #else /* CONFIG_SCHED_HRTICK */
  19642. static inline void hrtick_clear(struct rq *rq)
  19643. @@ -542,7 +547,7 @@
  19644. head->lastp = &node->next;
  19645. }
  19646. -void wake_up_q(struct wake_q_head *head)
  19647. +void __wake_up_q(struct wake_q_head *head, bool sleeper)
  19648. {
  19649. struct wake_q_node *node = head->first;
  19650. @@ -559,7 +564,10 @@
  19651. * wake_up_process() implies a wmb() to pair with the queueing
  19652. * in wake_q_add() so as not to miss wakeups.
  19653. */
  19654. - wake_up_process(task);
  19655. + if (sleeper)
  19656. + wake_up_lock_sleeper(task);
  19657. + else
  19658. + wake_up_process(task);
  19659. put_task_struct(task);
  19660. }
  19661. }
  19662. @@ -595,6 +603,38 @@
  19663. trace_sched_wake_idle_without_ipi(cpu);
  19664. }
  19665. +#ifdef CONFIG_PREEMPT_LAZY
  19666. +void resched_curr_lazy(struct rq *rq)
  19667. +{
  19668. + struct task_struct *curr = rq->curr;
  19669. + int cpu;
  19670. +
  19671. + if (!sched_feat(PREEMPT_LAZY)) {
  19672. + resched_curr(rq);
  19673. + return;
  19674. + }
  19675. +
  19676. + lockdep_assert_held(&rq->lock);
  19677. +
  19678. + if (test_tsk_need_resched(curr))
  19679. + return;
  19680. +
  19681. + if (test_tsk_need_resched_lazy(curr))
  19682. + return;
  19683. +
  19684. + set_tsk_need_resched_lazy(curr);
  19685. +
  19686. + cpu = cpu_of(rq);
  19687. + if (cpu == smp_processor_id())
  19688. + return;
  19689. +
  19690. + /* NEED_RESCHED_LAZY must be visible before we test polling */
  19691. + smp_mb();
  19692. + if (!tsk_is_polling(curr))
  19693. + smp_send_reschedule(cpu);
  19694. +}
  19695. +#endif
  19696. +
  19697. void resched_cpu(int cpu)
  19698. {
  19699. struct rq *rq = cpu_rq(cpu);
  19700. @@ -618,11 +658,14 @@
  19701. */
  19702. int get_nohz_timer_target(void)
  19703. {
  19704. - int i, cpu = smp_processor_id();
  19705. + int i, cpu;
  19706. struct sched_domain *sd;
  19707. + preempt_disable_rt();
  19708. + cpu = smp_processor_id();
  19709. +
  19710. if (!idle_cpu(cpu) && is_housekeeping_cpu(cpu))
  19711. - return cpu;
  19712. + goto preempt_en_rt;
  19713. rcu_read_lock();
  19714. for_each_domain(cpu, sd) {
  19715. @@ -638,6 +681,8 @@
  19716. cpu = housekeeping_any_cpu();
  19717. unlock:
  19718. rcu_read_unlock();
  19719. +preempt_en_rt:
  19720. + preempt_enable_rt();
  19721. return cpu;
  19722. }
  19723. /*
  19724. @@ -1171,6 +1216,11 @@
  19725. lockdep_assert_held(&p->pi_lock);
  19726. + if (__migrate_disabled(p)) {
  19727. + cpumask_copy(&p->cpus_allowed, new_mask);
  19728. + return;
  19729. + }
  19730. +
  19731. queued = task_on_rq_queued(p);
  19732. running = task_current(rq, p);
  19733. @@ -1193,6 +1243,84 @@
  19734. enqueue_task(rq, p, ENQUEUE_RESTORE);
  19735. }
  19736. +static DEFINE_PER_CPU(struct cpumask, sched_cpumasks);
  19737. +static DEFINE_MUTEX(sched_down_mutex);
  19738. +static cpumask_t sched_down_cpumask;
  19739. +
  19740. +void tell_sched_cpu_down_begin(int cpu)
  19741. +{
  19742. + mutex_lock(&sched_down_mutex);
  19743. + cpumask_set_cpu(cpu, &sched_down_cpumask);
  19744. + mutex_unlock(&sched_down_mutex);
  19745. +}
  19746. +
  19747. +void tell_sched_cpu_down_done(int cpu)
  19748. +{
  19749. + mutex_lock(&sched_down_mutex);
  19750. + cpumask_clear_cpu(cpu, &sched_down_cpumask);
  19751. + mutex_unlock(&sched_down_mutex);
  19752. +}
  19753. +
  19754. +/**
  19755. + * migrate_me - try to move the current task off this cpu
  19756. + *
  19757. + * Used by the pin_current_cpu() code to try to get tasks
  19758. + * to move off the current CPU as it is going down.
  19759. + * It will only move the task if the task isn't pinned to
  19760. + * the CPU (with migrate_disable, affinity or NO_SETAFFINITY)
  19761. + * and the task has to be in a RUNNING state. Otherwise the
  19762. + * movement of the task will wake it up (change its state
  19763. + * to running) when the task did not expect it.
  19764. + *
  19765. + * Returns 1 if it succeeded in moving the current task
  19766. + * 0 otherwise.
  19767. + */
  19768. +int migrate_me(void)
  19769. +{
  19770. + struct task_struct *p = current;
  19771. + struct migration_arg arg;
  19772. + struct cpumask *cpumask;
  19773. + struct cpumask *mask;
  19774. + unsigned long flags;
  19775. + unsigned int dest_cpu;
  19776. + struct rq *rq;
  19777. +
  19778. + /*
  19779. + * We can not migrate tasks bounded to a CPU or tasks not
  19780. + * running. The movement of the task will wake it up.
  19781. + */
  19782. + if (p->flags & PF_NO_SETAFFINITY || p->state)
  19783. + return 0;
  19784. +
  19785. + mutex_lock(&sched_down_mutex);
  19786. + rq = task_rq_lock(p, &flags);
  19787. +
  19788. + cpumask = this_cpu_ptr(&sched_cpumasks);
  19789. + mask = &p->cpus_allowed;
  19790. +
  19791. + cpumask_andnot(cpumask, mask, &sched_down_cpumask);
  19792. +
  19793. + if (!cpumask_weight(cpumask)) {
  19794. + /* It's only on this CPU? */
  19795. + task_rq_unlock(rq, p, &flags);
  19796. + mutex_unlock(&sched_down_mutex);
  19797. + return 0;
  19798. + }
  19799. +
  19800. + dest_cpu = cpumask_any_and(cpu_active_mask, cpumask);
  19801. +
  19802. + arg.task = p;
  19803. + arg.dest_cpu = dest_cpu;
  19804. +
  19805. + task_rq_unlock(rq, p, &flags);
  19806. +
  19807. + stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg);
  19808. + tlb_migrate_finish(p->mm);
  19809. + mutex_unlock(&sched_down_mutex);
  19810. +
  19811. + return 1;
  19812. +}
  19813. +
  19814. /*
  19815. * Change a given task's CPU affinity. Migrate the thread to a
  19816. * proper CPU and schedule it away if the CPU it's executing on
  19817. @@ -1232,7 +1360,7 @@
  19818. do_set_cpus_allowed(p, new_mask);
  19819. /* Can the task run on the task's current CPU? If so, we're done */
  19820. - if (cpumask_test_cpu(task_cpu(p), new_mask))
  19821. + if (cpumask_test_cpu(task_cpu(p), new_mask) || __migrate_disabled(p))
  19822. goto out;
  19823. dest_cpu = cpumask_any_and(cpu_active_mask, new_mask);
  19824. @@ -1408,6 +1536,18 @@
  19825. return ret;
  19826. }
  19827. +static bool check_task_state(struct task_struct *p, long match_state)
  19828. +{
  19829. + bool match = false;
  19830. +
  19831. + raw_spin_lock_irq(&p->pi_lock);
  19832. + if (p->state == match_state || p->saved_state == match_state)
  19833. + match = true;
  19834. + raw_spin_unlock_irq(&p->pi_lock);
  19835. +
  19836. + return match;
  19837. +}
  19838. +
  19839. /*
  19840. * wait_task_inactive - wait for a thread to unschedule.
  19841. *
  19842. @@ -1452,7 +1592,7 @@
  19843. * is actually now running somewhere else!
  19844. */
  19845. while (task_running(rq, p)) {
  19846. - if (match_state && unlikely(p->state != match_state))
  19847. + if (match_state && !check_task_state(p, match_state))
  19848. return 0;
  19849. cpu_relax();
  19850. }
  19851. @@ -1467,7 +1607,8 @@
  19852. running = task_running(rq, p);
  19853. queued = task_on_rq_queued(p);
  19854. ncsw = 0;
  19855. - if (!match_state || p->state == match_state)
  19856. + if (!match_state || p->state == match_state ||
  19857. + p->saved_state == match_state)
  19858. ncsw = p->nvcsw | LONG_MIN; /* sets MSB */
  19859. task_rq_unlock(rq, p, &flags);
  19860. @@ -1624,7 +1765,7 @@
  19861. {
  19862. lockdep_assert_held(&p->pi_lock);
  19863. - if (p->nr_cpus_allowed > 1)
  19864. + if (tsk_nr_cpus_allowed(p) > 1)
  19865. cpu = p->sched_class->select_task_rq(p, cpu, sd_flags, wake_flags);
  19866. /*
  19867. @@ -1704,10 +1845,6 @@
  19868. {
  19869. activate_task(rq, p, en_flags);
  19870. p->on_rq = TASK_ON_RQ_QUEUED;
  19871. -
  19872. - /* if a worker is waking up, notify workqueue */
  19873. - if (p->flags & PF_WQ_WORKER)
  19874. - wq_worker_waking_up(p, cpu_of(rq));
  19875. }
  19876. /*
  19877. @@ -1934,8 +2071,27 @@
  19878. */
  19879. smp_mb__before_spinlock();
  19880. raw_spin_lock_irqsave(&p->pi_lock, flags);
  19881. - if (!(p->state & state))
  19882. + if (!(p->state & state)) {
  19883. + /*
  19884. + * The task might be running due to a spinlock sleeper
  19885. + * wakeup. Check the saved state and set it to running
  19886. + * if the wakeup condition is true.
  19887. + */
  19888. + if (!(wake_flags & WF_LOCK_SLEEPER)) {
  19889. + if (p->saved_state & state) {
  19890. + p->saved_state = TASK_RUNNING;
  19891. + success = 1;
  19892. + }
  19893. + }
  19894. goto out;
  19895. + }
  19896. +
  19897. + /*
  19898. + * If this is a regular wakeup, then we can unconditionally
  19899. + * clear the saved state of a "lock sleeper".
  19900. + */
  19901. + if (!(wake_flags & WF_LOCK_SLEEPER))
  19902. + p->saved_state = TASK_RUNNING;
  19903. trace_sched_waking(p);
  19904. @@ -2005,52 +2161,6 @@
  19905. }
  19906. /**
  19907. - * try_to_wake_up_local - try to wake up a local task with rq lock held
  19908. - * @p: the thread to be awakened
  19909. - *
  19910. - * Put @p on the run-queue if it's not already there. The caller must
  19911. - * ensure that this_rq() is locked, @p is bound to this_rq() and not
  19912. - * the current task.
  19913. - */
  19914. -static void try_to_wake_up_local(struct task_struct *p)
  19915. -{
  19916. - struct rq *rq = task_rq(p);
  19917. -
  19918. - if (WARN_ON_ONCE(rq != this_rq()) ||
  19919. - WARN_ON_ONCE(p == current))
  19920. - return;
  19921. -
  19922. - lockdep_assert_held(&rq->lock);
  19923. -
  19924. - if (!raw_spin_trylock(&p->pi_lock)) {
  19925. - /*
  19926. - * This is OK, because current is on_cpu, which avoids it being
  19927. - * picked for load-balance and preemption/IRQs are still
  19928. - * disabled avoiding further scheduler activity on it and we've
  19929. - * not yet picked a replacement task.
  19930. - */
  19931. - lockdep_unpin_lock(&rq->lock);
  19932. - raw_spin_unlock(&rq->lock);
  19933. - raw_spin_lock(&p->pi_lock);
  19934. - raw_spin_lock(&rq->lock);
  19935. - lockdep_pin_lock(&rq->lock);
  19936. - }
  19937. -
  19938. - if (!(p->state & TASK_NORMAL))
  19939. - goto out;
  19940. -
  19941. - trace_sched_waking(p);
  19942. -
  19943. - if (!task_on_rq_queued(p))
  19944. - ttwu_activate(rq, p, ENQUEUE_WAKEUP);
  19945. -
  19946. - ttwu_do_wakeup(rq, p, 0);
  19947. - ttwu_stat(p, smp_processor_id(), 0);
  19948. -out:
  19949. - raw_spin_unlock(&p->pi_lock);
  19950. -}
  19951. -
  19952. -/**
  19953. * wake_up_process - Wake up a specific process
  19954. * @p: The process to be woken up.
  19955. *
  19956. @@ -2068,6 +2178,18 @@
  19957. }
  19958. EXPORT_SYMBOL(wake_up_process);
  19959. +/**
  19960. + * wake_up_lock_sleeper - Wake up a specific process blocked on a "sleeping lock"
  19961. + * @p: The process to be woken up.
  19962. + *
  19963. + * Same as wake_up_process() above, but wake_flags=WF_LOCK_SLEEPER to indicate
  19964. + * the nature of the wakeup.
  19965. + */
  19966. +int wake_up_lock_sleeper(struct task_struct *p)
  19967. +{
  19968. + return try_to_wake_up(p, TASK_ALL, WF_LOCK_SLEEPER);
  19969. +}
  19970. +
  19971. int wake_up_state(struct task_struct *p, unsigned int state)
  19972. {
  19973. return try_to_wake_up(p, state, 0);
  19974. @@ -2254,6 +2376,9 @@
  19975. p->on_cpu = 0;
  19976. #endif
  19977. init_task_preempt_count(p);
  19978. +#ifdef CONFIG_HAVE_PREEMPT_LAZY
  19979. + task_thread_info(p)->preempt_lazy_count = 0;
  19980. +#endif
  19981. #ifdef CONFIG_SMP
  19982. plist_node_init(&p->pushable_tasks, MAX_PRIO);
  19983. RB_CLEAR_NODE(&p->pushable_dl_tasks);
  19984. @@ -2578,8 +2703,12 @@
  19985. finish_arch_post_lock_switch();
  19986. fire_sched_in_preempt_notifiers(current);
  19987. + /*
  19988. + * We use mmdrop_delayed() here so we don't have to do the
  19989. + * full __mmdrop() when we are the last user.
  19990. + */
  19991. if (mm)
  19992. - mmdrop(mm);
  19993. + mmdrop_delayed(mm);
  19994. if (unlikely(prev_state == TASK_DEAD)) {
  19995. if (prev->sched_class->task_dead)
  19996. prev->sched_class->task_dead(prev);
  19997. @@ -2910,16 +3039,6 @@
  19998. }
  19999. #endif
  20000. -notrace unsigned long get_parent_ip(unsigned long addr)
  20001. -{
  20002. - if (in_lock_functions(addr)) {
  20003. - addr = CALLER_ADDR2;
  20004. - if (in_lock_functions(addr))
  20005. - addr = CALLER_ADDR3;
  20006. - }
  20007. - return addr;
  20008. -}
  20009. -
  20010. #if defined(CONFIG_PREEMPT) && (defined(CONFIG_DEBUG_PREEMPT) || \
  20011. defined(CONFIG_PREEMPT_TRACER))
  20012. @@ -2941,7 +3060,7 @@
  20013. PREEMPT_MASK - 10);
  20014. #endif
  20015. if (preempt_count() == val) {
  20016. - unsigned long ip = get_parent_ip(CALLER_ADDR1);
  20017. + unsigned long ip = get_lock_parent_ip();
  20018. #ifdef CONFIG_DEBUG_PREEMPT
  20019. current->preempt_disable_ip = ip;
  20020. #endif
  20021. @@ -2968,7 +3087,7 @@
  20022. #endif
  20023. if (preempt_count() == val)
  20024. - trace_preempt_on(CALLER_ADDR0, get_parent_ip(CALLER_ADDR1));
  20025. + trace_preempt_on(CALLER_ADDR0, get_lock_parent_ip());
  20026. __preempt_count_sub(val);
  20027. }
  20028. EXPORT_SYMBOL(preempt_count_sub);
  20029. @@ -3022,6 +3141,77 @@
  20030. schedstat_inc(this_rq(), sched_count);
  20031. }
  20032. +#if defined(CONFIG_PREEMPT_RT_FULL) && defined(CONFIG_SMP)
  20033. +
  20034. +void migrate_disable(void)
  20035. +{
  20036. + struct task_struct *p = current;
  20037. +
  20038. + if (in_atomic() || irqs_disabled()) {
  20039. +#ifdef CONFIG_SCHED_DEBUG
  20040. + p->migrate_disable_atomic++;
  20041. +#endif
  20042. + return;
  20043. + }
  20044. +
  20045. +#ifdef CONFIG_SCHED_DEBUG
  20046. + if (unlikely(p->migrate_disable_atomic)) {
  20047. + tracing_off();
  20048. + WARN_ON_ONCE(1);
  20049. + }
  20050. +#endif
  20051. +
  20052. + if (p->migrate_disable) {
  20053. + p->migrate_disable++;
  20054. + return;
  20055. + }
  20056. +
  20057. + preempt_disable();
  20058. + preempt_lazy_disable();
  20059. + pin_current_cpu();
  20060. + p->migrate_disable = 1;
  20061. + preempt_enable();
  20062. +}
  20063. +EXPORT_SYMBOL(migrate_disable);
  20064. +
  20065. +void migrate_enable(void)
  20066. +{
  20067. + struct task_struct *p = current;
  20068. +
  20069. + if (in_atomic() || irqs_disabled()) {
  20070. +#ifdef CONFIG_SCHED_DEBUG
  20071. + p->migrate_disable_atomic--;
  20072. +#endif
  20073. + return;
  20074. + }
  20075. +
  20076. +#ifdef CONFIG_SCHED_DEBUG
  20077. + if (unlikely(p->migrate_disable_atomic)) {
  20078. + tracing_off();
  20079. + WARN_ON_ONCE(1);
  20080. + }
  20081. +#endif
  20082. + WARN_ON_ONCE(p->migrate_disable <= 0);
  20083. +
  20084. + if (p->migrate_disable > 1) {
  20085. + p->migrate_disable--;
  20086. + return;
  20087. + }
  20088. +
  20089. + preempt_disable();
  20090. + /*
  20091. + * Clearing migrate_disable causes tsk_cpus_allowed to
  20092. + * show the tasks original cpu affinity.
  20093. + */
  20094. + p->migrate_disable = 0;
  20095. +
  20096. + unpin_current_cpu();
  20097. + preempt_enable();
  20098. + preempt_lazy_enable();
  20099. +}
  20100. +EXPORT_SYMBOL(migrate_enable);
  20101. +#endif
  20102. +
  20103. /*
  20104. * Pick up the highest-prio task:
  20105. */
  20106. @@ -3146,19 +3336,6 @@
  20107. } else {
  20108. deactivate_task(rq, prev, DEQUEUE_SLEEP);
  20109. prev->on_rq = 0;
  20110. -
  20111. - /*
  20112. - * If a worker went to sleep, notify and ask workqueue
  20113. - * whether it wants to wake up a task to maintain
  20114. - * concurrency.
  20115. - */
  20116. - if (prev->flags & PF_WQ_WORKER) {
  20117. - struct task_struct *to_wakeup;
  20118. -
  20119. - to_wakeup = wq_worker_sleeping(prev, cpu);
  20120. - if (to_wakeup)
  20121. - try_to_wake_up_local(to_wakeup);
  20122. - }
  20123. }
  20124. switch_count = &prev->nvcsw;
  20125. }
  20126. @@ -3168,6 +3345,7 @@
  20127. next = pick_next_task(rq, prev);
  20128. clear_tsk_need_resched(prev);
  20129. + clear_tsk_need_resched_lazy(prev);
  20130. clear_preempt_need_resched();
  20131. rq->clock_skip_update = 0;
  20132. @@ -3189,9 +3367,20 @@
  20133. static inline void sched_submit_work(struct task_struct *tsk)
  20134. {
  20135. - if (!tsk->state || tsk_is_pi_blocked(tsk))
  20136. + if (!tsk->state)
  20137. return;
  20138. /*
  20139. + * If a worker went to sleep, notify and ask workqueue whether
  20140. + * it wants to wake up a task to maintain concurrency.
  20141. + */
  20142. + if (tsk->flags & PF_WQ_WORKER)
  20143. + wq_worker_sleeping(tsk);
  20144. +
  20145. +
  20146. + if (tsk_is_pi_blocked(tsk))
  20147. + return;
  20148. +
  20149. + /*
  20150. * If we are going to sleep and we have plugged IO queued,
  20151. * make sure to submit it to avoid deadlocks.
  20152. */
  20153. @@ -3199,6 +3388,12 @@
  20154. blk_schedule_flush_plug(tsk);
  20155. }
  20156. +static void sched_update_worker(struct task_struct *tsk)
  20157. +{
  20158. + if (tsk->flags & PF_WQ_WORKER)
  20159. + wq_worker_running(tsk);
  20160. +}
  20161. +
  20162. asmlinkage __visible void __sched schedule(void)
  20163. {
  20164. struct task_struct *tsk = current;
  20165. @@ -3209,6 +3404,7 @@
  20166. __schedule(false);
  20167. sched_preempt_enable_no_resched();
  20168. } while (need_resched());
  20169. + sched_update_worker(tsk);
  20170. }
  20171. EXPORT_SYMBOL(schedule);
  20172. @@ -3257,6 +3453,30 @@
  20173. } while (need_resched());
  20174. }
  20175. +#ifdef CONFIG_PREEMPT_LAZY
  20176. +/*
  20177. + * If TIF_NEED_RESCHED is then we allow to be scheduled away since this is
  20178. + * set by a RT task. Oterwise we try to avoid beeing scheduled out as long as
  20179. + * preempt_lazy_count counter >0.
  20180. + */
  20181. +static __always_inline int preemptible_lazy(void)
  20182. +{
  20183. + if (test_thread_flag(TIF_NEED_RESCHED))
  20184. + return 1;
  20185. + if (current_thread_info()->preempt_lazy_count)
  20186. + return 0;
  20187. + return 1;
  20188. +}
  20189. +
  20190. +#else
  20191. +
  20192. +static int preemptible_lazy(void)
  20193. +{
  20194. + return 1;
  20195. +}
  20196. +
  20197. +#endif
  20198. +
  20199. #ifdef CONFIG_PREEMPT
  20200. /*
  20201. * this is the entry point to schedule() from in-kernel preemption
  20202. @@ -3271,6 +3491,8 @@
  20203. */
  20204. if (likely(!preemptible()))
  20205. return;
  20206. + if (!preemptible_lazy())
  20207. + return;
  20208. preempt_schedule_common();
  20209. }
  20210. @@ -3297,6 +3519,8 @@
  20211. if (likely(!preemptible()))
  20212. return;
  20213. + if (!preemptible_lazy())
  20214. + return;
  20215. do {
  20216. preempt_disable_notrace();
  20217. @@ -3306,7 +3530,16 @@
  20218. * an infinite recursion.
  20219. */
  20220. prev_ctx = exception_enter();
  20221. + /*
  20222. + * The add/subtract must not be traced by the function
  20223. + * tracer. But we still want to account for the
  20224. + * preempt off latency tracer. Since the _notrace versions
  20225. + * of add/subtract skip the accounting for latency tracer
  20226. + * we must force it manually.
  20227. + */
  20228. + start_critical_timings();
  20229. __schedule(true);
  20230. + stop_critical_timings();
  20231. exception_exit(prev_ctx);
  20232. preempt_enable_no_resched_notrace();
  20233. @@ -4650,6 +4883,7 @@
  20234. }
  20235. EXPORT_SYMBOL(__cond_resched_lock);
  20236. +#ifndef CONFIG_PREEMPT_RT_FULL
  20237. int __sched __cond_resched_softirq(void)
  20238. {
  20239. BUG_ON(!in_softirq());
  20240. @@ -4663,6 +4897,7 @@
  20241. return 0;
  20242. }
  20243. EXPORT_SYMBOL(__cond_resched_softirq);
  20244. +#endif
  20245. /**
  20246. * yield - yield the current processor to other threads.
  20247. @@ -5027,7 +5262,9 @@
  20248. /* Set the preempt count _outside_ the spinlocks! */
  20249. init_idle_preempt_count(idle, cpu);
  20250. -
  20251. +#ifdef CONFIG_HAVE_PREEMPT_LAZY
  20252. + task_thread_info(idle)->preempt_lazy_count = 0;
  20253. +#endif
  20254. /*
  20255. * The idle tasks have their own, simple scheduling class:
  20256. */
  20257. @@ -5168,6 +5405,8 @@
  20258. #endif /* CONFIG_NUMA_BALANCING */
  20259. #ifdef CONFIG_HOTPLUG_CPU
  20260. +static DEFINE_PER_CPU(struct mm_struct *, idle_last_mm);
  20261. +
  20262. /*
  20263. * Ensures that the idle task is using init_mm right before its cpu goes
  20264. * offline.
  20265. @@ -5182,7 +5421,11 @@
  20266. switch_mm(mm, &init_mm, current);
  20267. finish_arch_post_lock_switch();
  20268. }
  20269. - mmdrop(mm);
  20270. + /*
  20271. + * Defer the cleanup to an alive cpu. On RT we can neither
  20272. + * call mmdrop() nor mmdrop_delayed() from here.
  20273. + */
  20274. + per_cpu(idle_last_mm, smp_processor_id()) = mm;
  20275. }
  20276. /*
  20277. @@ -5555,6 +5798,10 @@
  20278. case CPU_DEAD:
  20279. calc_load_migrate(rq);
  20280. + if (per_cpu(idle_last_mm, cpu)) {
  20281. + mmdrop(per_cpu(idle_last_mm, cpu));
  20282. + per_cpu(idle_last_mm, cpu) = NULL;
  20283. + }
  20284. break;
  20285. #endif
  20286. }
  20287. @@ -7538,7 +7785,7 @@
  20288. #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
  20289. static inline int preempt_count_equals(int preempt_offset)
  20290. {
  20291. - int nested = preempt_count() + rcu_preempt_depth();
  20292. + int nested = preempt_count() + sched_rcu_preempt_depth();
  20293. return (nested == preempt_offset);
  20294. }
  20295. diff -Nur linux-4.4.13.orig/kernel/sched/cpudeadline.c linux-4.4.13/kernel/sched/cpudeadline.c
  20296. --- linux-4.4.13.orig/kernel/sched/cpudeadline.c 2016-06-08 03:14:51.000000000 +0200
  20297. +++ linux-4.4.13/kernel/sched/cpudeadline.c 2016-06-22 21:55:08.058523867 +0200
  20298. @@ -103,10 +103,10 @@
  20299. const struct sched_dl_entity *dl_se = &p->dl;
  20300. if (later_mask &&
  20301. - cpumask_and(later_mask, cp->free_cpus, &p->cpus_allowed)) {
  20302. + cpumask_and(later_mask, cp->free_cpus, tsk_cpus_allowed(p))) {
  20303. best_cpu = cpumask_any(later_mask);
  20304. goto out;
  20305. - } else if (cpumask_test_cpu(cpudl_maximum(cp), &p->cpus_allowed) &&
  20306. + } else if (cpumask_test_cpu(cpudl_maximum(cp), tsk_cpus_allowed(p)) &&
  20307. dl_time_before(dl_se->deadline, cp->elements[0].dl)) {
  20308. best_cpu = cpudl_maximum(cp);
  20309. if (later_mask)
  20310. diff -Nur linux-4.4.13.orig/kernel/sched/cpupri.c linux-4.4.13/kernel/sched/cpupri.c
  20311. --- linux-4.4.13.orig/kernel/sched/cpupri.c 2016-06-08 03:14:51.000000000 +0200
  20312. +++ linux-4.4.13/kernel/sched/cpupri.c 2016-06-22 21:55:08.058523867 +0200
  20313. @@ -103,11 +103,11 @@
  20314. if (skip)
  20315. continue;
  20316. - if (cpumask_any_and(&p->cpus_allowed, vec->mask) >= nr_cpu_ids)
  20317. + if (cpumask_any_and(tsk_cpus_allowed(p), vec->mask) >= nr_cpu_ids)
  20318. continue;
  20319. if (lowest_mask) {
  20320. - cpumask_and(lowest_mask, &p->cpus_allowed, vec->mask);
  20321. + cpumask_and(lowest_mask, tsk_cpus_allowed(p), vec->mask);
  20322. /*
  20323. * We have to ensure that we have at least one bit
  20324. diff -Nur linux-4.4.13.orig/kernel/sched/cputime.c linux-4.4.13/kernel/sched/cputime.c
  20325. --- linux-4.4.13.orig/kernel/sched/cputime.c 2016-06-08 03:14:51.000000000 +0200
  20326. +++ linux-4.4.13/kernel/sched/cputime.c 2016-06-22 21:55:08.058523867 +0200
  20327. @@ -680,7 +680,7 @@
  20328. {
  20329. unsigned long long delta = vtime_delta(tsk);
  20330. - WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_SLEEPING);
  20331. + WARN_ON_ONCE(tsk->vtime_snap_whence == VTIME_INACTIVE);
  20332. tsk->vtime_snap += delta;
  20333. /* CHECKME: always safe to convert nsecs to cputime? */
  20334. @@ -696,37 +696,37 @@
  20335. void vtime_account_system(struct task_struct *tsk)
  20336. {
  20337. - write_seqlock(&tsk->vtime_seqlock);
  20338. + write_seqcount_begin(&tsk->vtime_seqcount);
  20339. __vtime_account_system(tsk);
  20340. - write_sequnlock(&tsk->vtime_seqlock);
  20341. + write_seqcount_end(&tsk->vtime_seqcount);
  20342. }
  20343. void vtime_gen_account_irq_exit(struct task_struct *tsk)
  20344. {
  20345. - write_seqlock(&tsk->vtime_seqlock);
  20346. + write_seqcount_begin(&tsk->vtime_seqcount);
  20347. __vtime_account_system(tsk);
  20348. if (context_tracking_in_user())
  20349. tsk->vtime_snap_whence = VTIME_USER;
  20350. - write_sequnlock(&tsk->vtime_seqlock);
  20351. + write_seqcount_end(&tsk->vtime_seqcount);
  20352. }
  20353. void vtime_account_user(struct task_struct *tsk)
  20354. {
  20355. cputime_t delta_cpu;
  20356. - write_seqlock(&tsk->vtime_seqlock);
  20357. + write_seqcount_begin(&tsk->vtime_seqcount);
  20358. delta_cpu = get_vtime_delta(tsk);
  20359. tsk->vtime_snap_whence = VTIME_SYS;
  20360. account_user_time(tsk, delta_cpu, cputime_to_scaled(delta_cpu));
  20361. - write_sequnlock(&tsk->vtime_seqlock);
  20362. + write_seqcount_end(&tsk->vtime_seqcount);
  20363. }
  20364. void vtime_user_enter(struct task_struct *tsk)
  20365. {
  20366. - write_seqlock(&tsk->vtime_seqlock);
  20367. + write_seqcount_begin(&tsk->vtime_seqcount);
  20368. __vtime_account_system(tsk);
  20369. tsk->vtime_snap_whence = VTIME_USER;
  20370. - write_sequnlock(&tsk->vtime_seqlock);
  20371. + write_seqcount_end(&tsk->vtime_seqcount);
  20372. }
  20373. void vtime_guest_enter(struct task_struct *tsk)
  20374. @@ -738,19 +738,19 @@
  20375. * synchronization against the reader (task_gtime())
  20376. * that can thus safely catch up with a tickless delta.
  20377. */
  20378. - write_seqlock(&tsk->vtime_seqlock);
  20379. + write_seqcount_begin(&tsk->vtime_seqcount);
  20380. __vtime_account_system(tsk);
  20381. current->flags |= PF_VCPU;
  20382. - write_sequnlock(&tsk->vtime_seqlock);
  20383. + write_seqcount_end(&tsk->vtime_seqcount);
  20384. }
  20385. EXPORT_SYMBOL_GPL(vtime_guest_enter);
  20386. void vtime_guest_exit(struct task_struct *tsk)
  20387. {
  20388. - write_seqlock(&tsk->vtime_seqlock);
  20389. + write_seqcount_begin(&tsk->vtime_seqcount);
  20390. __vtime_account_system(tsk);
  20391. current->flags &= ~PF_VCPU;
  20392. - write_sequnlock(&tsk->vtime_seqlock);
  20393. + write_seqcount_end(&tsk->vtime_seqcount);
  20394. }
  20395. EXPORT_SYMBOL_GPL(vtime_guest_exit);
  20396. @@ -763,24 +763,26 @@
  20397. void arch_vtime_task_switch(struct task_struct *prev)
  20398. {
  20399. - write_seqlock(&prev->vtime_seqlock);
  20400. - prev->vtime_snap_whence = VTIME_SLEEPING;
  20401. - write_sequnlock(&prev->vtime_seqlock);
  20402. + write_seqcount_begin(&prev->vtime_seqcount);
  20403. + prev->vtime_snap_whence = VTIME_INACTIVE;
  20404. + write_seqcount_end(&prev->vtime_seqcount);
  20405. - write_seqlock(&current->vtime_seqlock);
  20406. + write_seqcount_begin(&current->vtime_seqcount);
  20407. current->vtime_snap_whence = VTIME_SYS;
  20408. current->vtime_snap = sched_clock_cpu(smp_processor_id());
  20409. - write_sequnlock(&current->vtime_seqlock);
  20410. + write_seqcount_end(&current->vtime_seqcount);
  20411. }
  20412. void vtime_init_idle(struct task_struct *t, int cpu)
  20413. {
  20414. unsigned long flags;
  20415. - write_seqlock_irqsave(&t->vtime_seqlock, flags);
  20416. + local_irq_save(flags);
  20417. + write_seqcount_begin(&t->vtime_seqcount);
  20418. t->vtime_snap_whence = VTIME_SYS;
  20419. t->vtime_snap = sched_clock_cpu(cpu);
  20420. - write_sequnlock_irqrestore(&t->vtime_seqlock, flags);
  20421. + write_seqcount_end(&t->vtime_seqcount);
  20422. + local_irq_restore(flags);
  20423. }
  20424. cputime_t task_gtime(struct task_struct *t)
  20425. @@ -792,13 +794,13 @@
  20426. return t->gtime;
  20427. do {
  20428. - seq = read_seqbegin(&t->vtime_seqlock);
  20429. + seq = read_seqcount_begin(&t->vtime_seqcount);
  20430. gtime = t->gtime;
  20431. if (t->flags & PF_VCPU)
  20432. gtime += vtime_delta(t);
  20433. - } while (read_seqretry(&t->vtime_seqlock, seq));
  20434. + } while (read_seqcount_retry(&t->vtime_seqcount, seq));
  20435. return gtime;
  20436. }
  20437. @@ -821,7 +823,7 @@
  20438. *udelta = 0;
  20439. *sdelta = 0;
  20440. - seq = read_seqbegin(&t->vtime_seqlock);
  20441. + seq = read_seqcount_begin(&t->vtime_seqcount);
  20442. if (u_dst)
  20443. *u_dst = *u_src;
  20444. @@ -829,7 +831,7 @@
  20445. *s_dst = *s_src;
  20446. /* Task is sleeping, nothing to add */
  20447. - if (t->vtime_snap_whence == VTIME_SLEEPING ||
  20448. + if (t->vtime_snap_whence == VTIME_INACTIVE ||
  20449. is_idle_task(t))
  20450. continue;
  20451. @@ -845,7 +847,7 @@
  20452. if (t->vtime_snap_whence == VTIME_SYS)
  20453. *sdelta = delta;
  20454. }
  20455. - } while (read_seqretry(&t->vtime_seqlock, seq));
  20456. + } while (read_seqcount_retry(&t->vtime_seqcount, seq));
  20457. }
  20458. diff -Nur linux-4.4.13.orig/kernel/sched/deadline.c linux-4.4.13/kernel/sched/deadline.c
  20459. --- linux-4.4.13.orig/kernel/sched/deadline.c 2016-06-08 03:14:51.000000000 +0200
  20460. +++ linux-4.4.13/kernel/sched/deadline.c 2016-06-22 21:55:08.058523867 +0200
  20461. @@ -134,7 +134,7 @@
  20462. {
  20463. struct task_struct *p = dl_task_of(dl_se);
  20464. - if (p->nr_cpus_allowed > 1)
  20465. + if (tsk_nr_cpus_allowed(p) > 1)
  20466. dl_rq->dl_nr_migratory++;
  20467. update_dl_migration(dl_rq);
  20468. @@ -144,7 +144,7 @@
  20469. {
  20470. struct task_struct *p = dl_task_of(dl_se);
  20471. - if (p->nr_cpus_allowed > 1)
  20472. + if (tsk_nr_cpus_allowed(p) > 1)
  20473. dl_rq->dl_nr_migratory--;
  20474. update_dl_migration(dl_rq);
  20475. @@ -697,6 +697,7 @@
  20476. hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  20477. timer->function = dl_task_timer;
  20478. + timer->irqsafe = 1;
  20479. }
  20480. static
  20481. @@ -989,7 +990,7 @@
  20482. enqueue_dl_entity(&p->dl, pi_se, flags);
  20483. - if (!task_current(rq, p) && p->nr_cpus_allowed > 1)
  20484. + if (!task_current(rq, p) && tsk_nr_cpus_allowed(p) > 1)
  20485. enqueue_pushable_dl_task(rq, p);
  20486. }
  20487. @@ -1067,9 +1068,9 @@
  20488. * try to make it stay here, it might be important.
  20489. */
  20490. if (unlikely(dl_task(curr)) &&
  20491. - (curr->nr_cpus_allowed < 2 ||
  20492. + (tsk_nr_cpus_allowed(curr) < 2 ||
  20493. !dl_entity_preempt(&p->dl, &curr->dl)) &&
  20494. - (p->nr_cpus_allowed > 1)) {
  20495. + (tsk_nr_cpus_allowed(p) > 1)) {
  20496. int target = find_later_rq(p);
  20497. if (target != -1 &&
  20498. @@ -1090,7 +1091,7 @@
  20499. * Current can't be migrated, useless to reschedule,
  20500. * let's hope p can move out.
  20501. */
  20502. - if (rq->curr->nr_cpus_allowed == 1 ||
  20503. + if (tsk_nr_cpus_allowed(rq->curr) == 1 ||
  20504. cpudl_find(&rq->rd->cpudl, rq->curr, NULL) == -1)
  20505. return;
  20506. @@ -1098,7 +1099,7 @@
  20507. * p is migratable, so let's not schedule it and
  20508. * see if it is pushed or pulled somewhere else.
  20509. */
  20510. - if (p->nr_cpus_allowed != 1 &&
  20511. + if (tsk_nr_cpus_allowed(p) != 1 &&
  20512. cpudl_find(&rq->rd->cpudl, p, NULL) != -1)
  20513. return;
  20514. @@ -1212,7 +1213,7 @@
  20515. {
  20516. update_curr_dl(rq);
  20517. - if (on_dl_rq(&p->dl) && p->nr_cpus_allowed > 1)
  20518. + if (on_dl_rq(&p->dl) && tsk_nr_cpus_allowed(p) > 1)
  20519. enqueue_pushable_dl_task(rq, p);
  20520. }
  20521. @@ -1335,7 +1336,7 @@
  20522. if (unlikely(!later_mask))
  20523. return -1;
  20524. - if (task->nr_cpus_allowed == 1)
  20525. + if (tsk_nr_cpus_allowed(task) == 1)
  20526. return -1;
  20527. /*
  20528. @@ -1441,7 +1442,7 @@
  20529. if (double_lock_balance(rq, later_rq)) {
  20530. if (unlikely(task_rq(task) != rq ||
  20531. !cpumask_test_cpu(later_rq->cpu,
  20532. - &task->cpus_allowed) ||
  20533. + tsk_cpus_allowed(task)) ||
  20534. task_running(rq, task) ||
  20535. !task_on_rq_queued(task))) {
  20536. double_unlock_balance(rq, later_rq);
  20537. @@ -1480,7 +1481,7 @@
  20538. BUG_ON(rq->cpu != task_cpu(p));
  20539. BUG_ON(task_current(rq, p));
  20540. - BUG_ON(p->nr_cpus_allowed <= 1);
  20541. + BUG_ON(tsk_nr_cpus_allowed(p) <= 1);
  20542. BUG_ON(!task_on_rq_queued(p));
  20543. BUG_ON(!dl_task(p));
  20544. @@ -1519,7 +1520,7 @@
  20545. */
  20546. if (dl_task(rq->curr) &&
  20547. dl_time_before(next_task->dl.deadline, rq->curr->dl.deadline) &&
  20548. - rq->curr->nr_cpus_allowed > 1) {
  20549. + tsk_nr_cpus_allowed(rq->curr) > 1) {
  20550. resched_curr(rq);
  20551. return 0;
  20552. }
  20553. @@ -1666,9 +1667,9 @@
  20554. {
  20555. if (!task_running(rq, p) &&
  20556. !test_tsk_need_resched(rq->curr) &&
  20557. - p->nr_cpus_allowed > 1 &&
  20558. + tsk_nr_cpus_allowed(p) > 1 &&
  20559. dl_task(rq->curr) &&
  20560. - (rq->curr->nr_cpus_allowed < 2 ||
  20561. + (tsk_nr_cpus_allowed(rq->curr) < 2 ||
  20562. !dl_entity_preempt(&p->dl, &rq->curr->dl))) {
  20563. push_dl_tasks(rq);
  20564. }
  20565. @@ -1769,7 +1770,7 @@
  20566. {
  20567. if (task_on_rq_queued(p) && rq->curr != p) {
  20568. #ifdef CONFIG_SMP
  20569. - if (p->nr_cpus_allowed > 1 && rq->dl.overloaded)
  20570. + if (tsk_nr_cpus_allowed(p) > 1 && rq->dl.overloaded)
  20571. queue_push_tasks(rq);
  20572. #else
  20573. if (dl_task(rq->curr))
  20574. diff -Nur linux-4.4.13.orig/kernel/sched/debug.c linux-4.4.13/kernel/sched/debug.c
  20575. --- linux-4.4.13.orig/kernel/sched/debug.c 2016-06-08 03:14:51.000000000 +0200
  20576. +++ linux-4.4.13/kernel/sched/debug.c 2016-06-22 21:55:08.058523867 +0200
  20577. @@ -251,6 +251,9 @@
  20578. P(rt_throttled);
  20579. PN(rt_time);
  20580. PN(rt_runtime);
  20581. +#ifdef CONFIG_SMP
  20582. + P(rt_nr_migratory);
  20583. +#endif
  20584. #undef PN
  20585. #undef P
  20586. @@ -635,6 +638,10 @@
  20587. #endif
  20588. P(policy);
  20589. P(prio);
  20590. +#ifdef CONFIG_PREEMPT_RT_FULL
  20591. + P(migrate_disable);
  20592. +#endif
  20593. + P(nr_cpus_allowed);
  20594. #undef PN
  20595. #undef __PN
  20596. #undef P
  20597. diff -Nur linux-4.4.13.orig/kernel/sched/fair.c linux-4.4.13/kernel/sched/fair.c
  20598. --- linux-4.4.13.orig/kernel/sched/fair.c 2016-06-08 03:14:51.000000000 +0200
  20599. +++ linux-4.4.13/kernel/sched/fair.c 2016-06-22 21:55:08.058523867 +0200
  20600. @@ -3135,7 +3135,7 @@
  20601. ideal_runtime = sched_slice(cfs_rq, curr);
  20602. delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime;
  20603. if (delta_exec > ideal_runtime) {
  20604. - resched_curr(rq_of(cfs_rq));
  20605. + resched_curr_lazy(rq_of(cfs_rq));
  20606. /*
  20607. * The current task ran long enough, ensure it doesn't get
  20608. * re-elected due to buddy favours.
  20609. @@ -3159,7 +3159,7 @@
  20610. return;
  20611. if (delta > ideal_runtime)
  20612. - resched_curr(rq_of(cfs_rq));
  20613. + resched_curr_lazy(rq_of(cfs_rq));
  20614. }
  20615. static void
  20616. @@ -3299,7 +3299,7 @@
  20617. * validating it and just reschedule.
  20618. */
  20619. if (queued) {
  20620. - resched_curr(rq_of(cfs_rq));
  20621. + resched_curr_lazy(rq_of(cfs_rq));
  20622. return;
  20623. }
  20624. /*
  20625. @@ -3481,7 +3481,7 @@
  20626. * hierarchy can be throttled
  20627. */
  20628. if (!assign_cfs_rq_runtime(cfs_rq) && likely(cfs_rq->curr))
  20629. - resched_curr(rq_of(cfs_rq));
  20630. + resched_curr_lazy(rq_of(cfs_rq));
  20631. }
  20632. static __always_inline
  20633. @@ -4093,7 +4093,7 @@
  20634. if (delta < 0) {
  20635. if (rq->curr == p)
  20636. - resched_curr(rq);
  20637. + resched_curr_lazy(rq);
  20638. return;
  20639. }
  20640. hrtick_start(rq, delta);
  20641. @@ -5177,7 +5177,7 @@
  20642. return;
  20643. preempt:
  20644. - resched_curr(rq);
  20645. + resched_curr_lazy(rq);
  20646. /*
  20647. * Only set the backward buddy when the current task is still
  20648. * on the rq. This can happen when a wakeup gets interleaved
  20649. @@ -7928,7 +7928,7 @@
  20650. * 'current' within the tree based on its new key value.
  20651. */
  20652. swap(curr->vruntime, se->vruntime);
  20653. - resched_curr(rq);
  20654. + resched_curr_lazy(rq);
  20655. }
  20656. se->vruntime -= cfs_rq->min_vruntime;
  20657. @@ -7953,7 +7953,7 @@
  20658. */
  20659. if (rq->curr == p) {
  20660. if (p->prio > oldprio)
  20661. - resched_curr(rq);
  20662. + resched_curr_lazy(rq);
  20663. } else
  20664. check_preempt_curr(rq, p, 0);
  20665. }
  20666. diff -Nur linux-4.4.13.orig/kernel/sched/features.h linux-4.4.13/kernel/sched/features.h
  20667. --- linux-4.4.13.orig/kernel/sched/features.h 2016-06-08 03:14:51.000000000 +0200
  20668. +++ linux-4.4.13/kernel/sched/features.h 2016-06-22 21:55:08.062523867 +0200
  20669. @@ -45,11 +45,19 @@
  20670. */
  20671. SCHED_FEAT(NONTASK_CAPACITY, true)
  20672. +#ifdef CONFIG_PREEMPT_RT_FULL
  20673. +SCHED_FEAT(TTWU_QUEUE, false)
  20674. +# ifdef CONFIG_PREEMPT_LAZY
  20675. +SCHED_FEAT(PREEMPT_LAZY, true)
  20676. +# endif
  20677. +#else
  20678. +
  20679. /*
  20680. * Queue remote wakeups on the target CPU and process them
  20681. * using the scheduler IPI. Reduces rq->lock contention/bounces.
  20682. */
  20683. SCHED_FEAT(TTWU_QUEUE, true)
  20684. +#endif
  20685. #ifdef HAVE_RT_PUSH_IPI
  20686. /*
  20687. diff -Nur linux-4.4.13.orig/kernel/sched/Makefile linux-4.4.13/kernel/sched/Makefile
  20688. --- linux-4.4.13.orig/kernel/sched/Makefile 2016-06-08 03:14:51.000000000 +0200
  20689. +++ linux-4.4.13/kernel/sched/Makefile 2016-06-22 21:55:08.062523867 +0200
  20690. @@ -13,7 +13,7 @@
  20691. obj-y += core.o loadavg.o clock.o cputime.o
  20692. obj-y += idle_task.o fair.o rt.o deadline.o stop_task.o
  20693. -obj-y += wait.o completion.o idle.o
  20694. +obj-y += wait.o swait.o work-simple.o completion.o idle.o
  20695. obj-$(CONFIG_SMP) += cpupri.o cpudeadline.o
  20696. obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o
  20697. obj-$(CONFIG_SCHEDSTATS) += stats.o
  20698. diff -Nur linux-4.4.13.orig/kernel/sched/rt.c linux-4.4.13/kernel/sched/rt.c
  20699. --- linux-4.4.13.orig/kernel/sched/rt.c 2016-06-08 03:14:51.000000000 +0200
  20700. +++ linux-4.4.13/kernel/sched/rt.c 2016-06-22 21:55:08.062523867 +0200
  20701. @@ -47,6 +47,7 @@
  20702. hrtimer_init(&rt_b->rt_period_timer,
  20703. CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  20704. + rt_b->rt_period_timer.irqsafe = 1;
  20705. rt_b->rt_period_timer.function = sched_rt_period_timer;
  20706. }
  20707. @@ -93,6 +94,7 @@
  20708. rt_rq->push_cpu = nr_cpu_ids;
  20709. raw_spin_lock_init(&rt_rq->push_lock);
  20710. init_irq_work(&rt_rq->push_work, push_irq_work_func);
  20711. + rt_rq->push_work.flags |= IRQ_WORK_HARD_IRQ;
  20712. #endif
  20713. #endif /* CONFIG_SMP */
  20714. /* We start is dequeued state, because no RT tasks are queued */
  20715. @@ -326,7 +328,7 @@
  20716. rt_rq = &rq_of_rt_rq(rt_rq)->rt;
  20717. rt_rq->rt_nr_total++;
  20718. - if (p->nr_cpus_allowed > 1)
  20719. + if (tsk_nr_cpus_allowed(p) > 1)
  20720. rt_rq->rt_nr_migratory++;
  20721. update_rt_migration(rt_rq);
  20722. @@ -343,7 +345,7 @@
  20723. rt_rq = &rq_of_rt_rq(rt_rq)->rt;
  20724. rt_rq->rt_nr_total--;
  20725. - if (p->nr_cpus_allowed > 1)
  20726. + if (tsk_nr_cpus_allowed(p) > 1)
  20727. rt_rq->rt_nr_migratory--;
  20728. update_rt_migration(rt_rq);
  20729. @@ -1262,7 +1264,7 @@
  20730. enqueue_rt_entity(rt_se, flags & ENQUEUE_HEAD);
  20731. - if (!task_current(rq, p) && p->nr_cpus_allowed > 1)
  20732. + if (!task_current(rq, p) && tsk_nr_cpus_allowed(p) > 1)
  20733. enqueue_pushable_task(rq, p);
  20734. }
  20735. @@ -1351,7 +1353,7 @@
  20736. * will have to sort it out.
  20737. */
  20738. if (curr && unlikely(rt_task(curr)) &&
  20739. - (curr->nr_cpus_allowed < 2 ||
  20740. + (tsk_nr_cpus_allowed(curr) < 2 ||
  20741. curr->prio <= p->prio)) {
  20742. int target = find_lowest_rq(p);
  20743. @@ -1375,7 +1377,7 @@
  20744. * Current can't be migrated, useless to reschedule,
  20745. * let's hope p can move out.
  20746. */
  20747. - if (rq->curr->nr_cpus_allowed == 1 ||
  20748. + if (tsk_nr_cpus_allowed(rq->curr) == 1 ||
  20749. !cpupri_find(&rq->rd->cpupri, rq->curr, NULL))
  20750. return;
  20751. @@ -1383,7 +1385,7 @@
  20752. * p is migratable, so let's not schedule it and
  20753. * see if it is pushed or pulled somewhere else.
  20754. */
  20755. - if (p->nr_cpus_allowed != 1
  20756. + if (tsk_nr_cpus_allowed(p) != 1
  20757. && cpupri_find(&rq->rd->cpupri, p, NULL))
  20758. return;
  20759. @@ -1517,7 +1519,7 @@
  20760. * The previous task needs to be made eligible for pushing
  20761. * if it is still active
  20762. */
  20763. - if (on_rt_rq(&p->rt) && p->nr_cpus_allowed > 1)
  20764. + if (on_rt_rq(&p->rt) && tsk_nr_cpus_allowed(p) > 1)
  20765. enqueue_pushable_task(rq, p);
  20766. }
  20767. @@ -1567,7 +1569,7 @@
  20768. if (unlikely(!lowest_mask))
  20769. return -1;
  20770. - if (task->nr_cpus_allowed == 1)
  20771. + if (tsk_nr_cpus_allowed(task) == 1)
  20772. return -1; /* No other targets possible */
  20773. if (!cpupri_find(&task_rq(task)->rd->cpupri, task, lowest_mask))
  20774. @@ -1699,7 +1701,7 @@
  20775. BUG_ON(rq->cpu != task_cpu(p));
  20776. BUG_ON(task_current(rq, p));
  20777. - BUG_ON(p->nr_cpus_allowed <= 1);
  20778. + BUG_ON(tsk_nr_cpus_allowed(p) <= 1);
  20779. BUG_ON(!task_on_rq_queued(p));
  20780. BUG_ON(!rt_task(p));
  20781. @@ -2059,9 +2061,9 @@
  20782. {
  20783. if (!task_running(rq, p) &&
  20784. !test_tsk_need_resched(rq->curr) &&
  20785. - p->nr_cpus_allowed > 1 &&
  20786. + tsk_nr_cpus_allowed(p) > 1 &&
  20787. (dl_task(rq->curr) || rt_task(rq->curr)) &&
  20788. - (rq->curr->nr_cpus_allowed < 2 ||
  20789. + (tsk_nr_cpus_allowed(rq->curr) < 2 ||
  20790. rq->curr->prio <= p->prio))
  20791. push_rt_tasks(rq);
  20792. }
  20793. @@ -2134,7 +2136,7 @@
  20794. */
  20795. if (task_on_rq_queued(p) && rq->curr != p) {
  20796. #ifdef CONFIG_SMP
  20797. - if (p->nr_cpus_allowed > 1 && rq->rt.overloaded)
  20798. + if (tsk_nr_cpus_allowed(p) > 1 && rq->rt.overloaded)
  20799. queue_push_tasks(rq);
  20800. #else
  20801. if (p->prio < rq->curr->prio)
  20802. diff -Nur linux-4.4.13.orig/kernel/sched/sched.h linux-4.4.13/kernel/sched/sched.h
  20803. --- linux-4.4.13.orig/kernel/sched/sched.h 2016-06-08 03:14:51.000000000 +0200
  20804. +++ linux-4.4.13/kernel/sched/sched.h 2016-06-22 21:55:08.062523867 +0200
  20805. @@ -1100,6 +1100,7 @@
  20806. #define WF_SYNC 0x01 /* waker goes to sleep after wakeup */
  20807. #define WF_FORK 0x02 /* child wakeup after fork */
  20808. #define WF_MIGRATED 0x4 /* internal use, task got migrated */
  20809. +#define WF_LOCK_SLEEPER 0x08 /* wakeup spinlock "sleeper" */
  20810. /*
  20811. * To aid in avoiding the subversion of "niceness" due to uneven distribution
  20812. @@ -1299,6 +1300,15 @@
  20813. extern void resched_curr(struct rq *rq);
  20814. extern void resched_cpu(int cpu);
  20815. +#ifdef CONFIG_PREEMPT_LAZY
  20816. +extern void resched_curr_lazy(struct rq *rq);
  20817. +#else
  20818. +static inline void resched_curr_lazy(struct rq *rq)
  20819. +{
  20820. + resched_curr(rq);
  20821. +}
  20822. +#endif
  20823. +
  20824. extern struct rt_bandwidth def_rt_bandwidth;
  20825. extern void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime);
  20826. diff -Nur linux-4.4.13.orig/kernel/sched/swait.c linux-4.4.13/kernel/sched/swait.c
  20827. --- linux-4.4.13.orig/kernel/sched/swait.c 1970-01-01 01:00:00.000000000 +0100
  20828. +++ linux-4.4.13/kernel/sched/swait.c 2016-06-22 21:55:08.062523867 +0200
  20829. @@ -0,0 +1,143 @@
  20830. +#include <linux/sched.h>
  20831. +#include <linux/swait.h>
  20832. +#include <linux/suspend.h>
  20833. +
  20834. +void __init_swait_queue_head(struct swait_queue_head *q, const char *name,
  20835. + struct lock_class_key *key)
  20836. +{
  20837. + raw_spin_lock_init(&q->lock);
  20838. + lockdep_set_class_and_name(&q->lock, key, name);
  20839. + INIT_LIST_HEAD(&q->task_list);
  20840. +}
  20841. +EXPORT_SYMBOL(__init_swait_queue_head);
  20842. +
  20843. +/*
  20844. + * The thing about the wake_up_state() return value; I think we can ignore it.
  20845. + *
  20846. + * If for some reason it would return 0, that means the previously waiting
  20847. + * task is already running, so it will observe condition true (or has already).
  20848. + */
  20849. +void swake_up_locked(struct swait_queue_head *q)
  20850. +{
  20851. + struct swait_queue *curr;
  20852. +
  20853. + if (list_empty(&q->task_list))
  20854. + return;
  20855. +
  20856. + curr = list_first_entry(&q->task_list, typeof(*curr), task_list);
  20857. + wake_up_process(curr->task);
  20858. + list_del_init(&curr->task_list);
  20859. +}
  20860. +EXPORT_SYMBOL(swake_up_locked);
  20861. +
  20862. +void swake_up_all_locked(struct swait_queue_head *q)
  20863. +{
  20864. + struct swait_queue *curr;
  20865. + int wakes = 0;
  20866. +
  20867. + while (!list_empty(&q->task_list)) {
  20868. +
  20869. + curr = list_first_entry(&q->task_list, typeof(*curr),
  20870. + task_list);
  20871. + wake_up_process(curr->task);
  20872. + list_del_init(&curr->task_list);
  20873. + wakes++;
  20874. + }
  20875. + if (pm_in_action)
  20876. + return;
  20877. + WARN(wakes > 2, "complate_all() with %d waiters\n", wakes);
  20878. +}
  20879. +EXPORT_SYMBOL(swake_up_all_locked);
  20880. +
  20881. +void swake_up(struct swait_queue_head *q)
  20882. +{
  20883. + unsigned long flags;
  20884. +
  20885. + if (!swait_active(q))
  20886. + return;
  20887. +
  20888. + raw_spin_lock_irqsave(&q->lock, flags);
  20889. + swake_up_locked(q);
  20890. + raw_spin_unlock_irqrestore(&q->lock, flags);
  20891. +}
  20892. +EXPORT_SYMBOL(swake_up);
  20893. +
  20894. +/*
  20895. + * Does not allow usage from IRQ disabled, since we must be able to
  20896. + * release IRQs to guarantee bounded hold time.
  20897. + */
  20898. +void swake_up_all(struct swait_queue_head *q)
  20899. +{
  20900. + struct swait_queue *curr;
  20901. + LIST_HEAD(tmp);
  20902. +
  20903. + if (!swait_active(q))
  20904. + return;
  20905. +
  20906. + raw_spin_lock_irq(&q->lock);
  20907. + list_splice_init(&q->task_list, &tmp);
  20908. + while (!list_empty(&tmp)) {
  20909. + curr = list_first_entry(&tmp, typeof(*curr), task_list);
  20910. +
  20911. + wake_up_state(curr->task, TASK_NORMAL);
  20912. + list_del_init(&curr->task_list);
  20913. +
  20914. + if (list_empty(&tmp))
  20915. + break;
  20916. +
  20917. + raw_spin_unlock_irq(&q->lock);
  20918. + raw_spin_lock_irq(&q->lock);
  20919. + }
  20920. + raw_spin_unlock_irq(&q->lock);
  20921. +}
  20922. +EXPORT_SYMBOL(swake_up_all);
  20923. +
  20924. +void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait)
  20925. +{
  20926. + wait->task = current;
  20927. + if (list_empty(&wait->task_list))
  20928. + list_add(&wait->task_list, &q->task_list);
  20929. +}
  20930. +
  20931. +void prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait, int state)
  20932. +{
  20933. + unsigned long flags;
  20934. +
  20935. + raw_spin_lock_irqsave(&q->lock, flags);
  20936. + __prepare_to_swait(q, wait);
  20937. + set_current_state(state);
  20938. + raw_spin_unlock_irqrestore(&q->lock, flags);
  20939. +}
  20940. +EXPORT_SYMBOL(prepare_to_swait);
  20941. +
  20942. +long prepare_to_swait_event(struct swait_queue_head *q, struct swait_queue *wait, int state)
  20943. +{
  20944. + if (signal_pending_state(state, current))
  20945. + return -ERESTARTSYS;
  20946. +
  20947. + prepare_to_swait(q, wait, state);
  20948. +
  20949. + return 0;
  20950. +}
  20951. +EXPORT_SYMBOL(prepare_to_swait_event);
  20952. +
  20953. +void __finish_swait(struct swait_queue_head *q, struct swait_queue *wait)
  20954. +{
  20955. + __set_current_state(TASK_RUNNING);
  20956. + if (!list_empty(&wait->task_list))
  20957. + list_del_init(&wait->task_list);
  20958. +}
  20959. +
  20960. +void finish_swait(struct swait_queue_head *q, struct swait_queue *wait)
  20961. +{
  20962. + unsigned long flags;
  20963. +
  20964. + __set_current_state(TASK_RUNNING);
  20965. +
  20966. + if (!list_empty_careful(&wait->task_list)) {
  20967. + raw_spin_lock_irqsave(&q->lock, flags);
  20968. + list_del_init(&wait->task_list);
  20969. + raw_spin_unlock_irqrestore(&q->lock, flags);
  20970. + }
  20971. +}
  20972. +EXPORT_SYMBOL(finish_swait);
  20973. diff -Nur linux-4.4.13.orig/kernel/sched/work-simple.c linux-4.4.13/kernel/sched/work-simple.c
  20974. --- linux-4.4.13.orig/kernel/sched/work-simple.c 1970-01-01 01:00:00.000000000 +0100
  20975. +++ linux-4.4.13/kernel/sched/work-simple.c 2016-06-22 21:55:08.062523867 +0200
  20976. @@ -0,0 +1,173 @@
  20977. +/*
  20978. + * Copyright (C) 2014 BMW Car IT GmbH, Daniel Wagner daniel.wagner@bmw-carit.de
  20979. + *
  20980. + * Provides a framework for enqueuing callbacks from irq context
  20981. + * PREEMPT_RT_FULL safe. The callbacks are executed in kthread context.
  20982. + */
  20983. +
  20984. +#include <linux/swait.h>
  20985. +#include <linux/work-simple.h>
  20986. +#include <linux/kthread.h>
  20987. +#include <linux/slab.h>
  20988. +#include <linux/spinlock.h>
  20989. +#include <linux/export.h>
  20990. +
  20991. +#define SWORK_EVENT_PENDING (1 << 0)
  20992. +
  20993. +static DEFINE_MUTEX(worker_mutex);
  20994. +static struct sworker *glob_worker;
  20995. +
  20996. +struct sworker {
  20997. + struct list_head events;
  20998. + struct swait_queue_head wq;
  20999. +
  21000. + raw_spinlock_t lock;
  21001. +
  21002. + struct task_struct *task;
  21003. + int refs;
  21004. +};
  21005. +
  21006. +static bool swork_readable(struct sworker *worker)
  21007. +{
  21008. + bool r;
  21009. +
  21010. + if (kthread_should_stop())
  21011. + return true;
  21012. +
  21013. + raw_spin_lock_irq(&worker->lock);
  21014. + r = !list_empty(&worker->events);
  21015. + raw_spin_unlock_irq(&worker->lock);
  21016. +
  21017. + return r;
  21018. +}
  21019. +
  21020. +static int swork_kthread(void *arg)
  21021. +{
  21022. + struct sworker *worker = arg;
  21023. +
  21024. + for (;;) {
  21025. + swait_event_interruptible(worker->wq,
  21026. + swork_readable(worker));
  21027. + if (kthread_should_stop())
  21028. + break;
  21029. +
  21030. + raw_spin_lock_irq(&worker->lock);
  21031. + while (!list_empty(&worker->events)) {
  21032. + struct swork_event *sev;
  21033. +
  21034. + sev = list_first_entry(&worker->events,
  21035. + struct swork_event, item);
  21036. + list_del(&sev->item);
  21037. + raw_spin_unlock_irq(&worker->lock);
  21038. +
  21039. + WARN_ON_ONCE(!test_and_clear_bit(SWORK_EVENT_PENDING,
  21040. + &sev->flags));
  21041. + sev->func(sev);
  21042. + raw_spin_lock_irq(&worker->lock);
  21043. + }
  21044. + raw_spin_unlock_irq(&worker->lock);
  21045. + }
  21046. + return 0;
  21047. +}
  21048. +
  21049. +static struct sworker *swork_create(void)
  21050. +{
  21051. + struct sworker *worker;
  21052. +
  21053. + worker = kzalloc(sizeof(*worker), GFP_KERNEL);
  21054. + if (!worker)
  21055. + return ERR_PTR(-ENOMEM);
  21056. +
  21057. + INIT_LIST_HEAD(&worker->events);
  21058. + raw_spin_lock_init(&worker->lock);
  21059. + init_swait_queue_head(&worker->wq);
  21060. +
  21061. + worker->task = kthread_run(swork_kthread, worker, "kswork");
  21062. + if (IS_ERR(worker->task)) {
  21063. + kfree(worker);
  21064. + return ERR_PTR(-ENOMEM);
  21065. + }
  21066. +
  21067. + return worker;
  21068. +}
  21069. +
  21070. +static void swork_destroy(struct sworker *worker)
  21071. +{
  21072. + kthread_stop(worker->task);
  21073. +
  21074. + WARN_ON(!list_empty(&worker->events));
  21075. + kfree(worker);
  21076. +}
  21077. +
  21078. +/**
  21079. + * swork_queue - queue swork
  21080. + *
  21081. + * Returns %false if @work was already on a queue, %true otherwise.
  21082. + *
  21083. + * The work is queued and processed on a random CPU
  21084. + */
  21085. +bool swork_queue(struct swork_event *sev)
  21086. +{
  21087. + unsigned long flags;
  21088. +
  21089. + if (test_and_set_bit(SWORK_EVENT_PENDING, &sev->flags))
  21090. + return false;
  21091. +
  21092. + raw_spin_lock_irqsave(&glob_worker->lock, flags);
  21093. + list_add_tail(&sev->item, &glob_worker->events);
  21094. + raw_spin_unlock_irqrestore(&glob_worker->lock, flags);
  21095. +
  21096. + swake_up(&glob_worker->wq);
  21097. + return true;
  21098. +}
  21099. +EXPORT_SYMBOL_GPL(swork_queue);
  21100. +
  21101. +/**
  21102. + * swork_get - get an instance of the sworker
  21103. + *
  21104. + * Returns an negative error code if the initialization if the worker did not
  21105. + * work, %0 otherwise.
  21106. + *
  21107. + */
  21108. +int swork_get(void)
  21109. +{
  21110. + struct sworker *worker;
  21111. +
  21112. + mutex_lock(&worker_mutex);
  21113. + if (!glob_worker) {
  21114. + worker = swork_create();
  21115. + if (IS_ERR(worker)) {
  21116. + mutex_unlock(&worker_mutex);
  21117. + return -ENOMEM;
  21118. + }
  21119. +
  21120. + glob_worker = worker;
  21121. + }
  21122. +
  21123. + glob_worker->refs++;
  21124. + mutex_unlock(&worker_mutex);
  21125. +
  21126. + return 0;
  21127. +}
  21128. +EXPORT_SYMBOL_GPL(swork_get);
  21129. +
  21130. +/**
  21131. + * swork_put - puts an instance of the sworker
  21132. + *
  21133. + * Will destroy the sworker thread. This function must not be called until all
  21134. + * queued events have been completed.
  21135. + */
  21136. +void swork_put(void)
  21137. +{
  21138. + mutex_lock(&worker_mutex);
  21139. +
  21140. + glob_worker->refs--;
  21141. + if (glob_worker->refs > 0)
  21142. + goto out;
  21143. +
  21144. + swork_destroy(glob_worker);
  21145. + glob_worker = NULL;
  21146. +out:
  21147. + mutex_unlock(&worker_mutex);
  21148. +}
  21149. +EXPORT_SYMBOL_GPL(swork_put);
  21150. diff -Nur linux-4.4.13.orig/kernel/signal.c linux-4.4.13/kernel/signal.c
  21151. --- linux-4.4.13.orig/kernel/signal.c 2016-06-08 03:14:51.000000000 +0200
  21152. +++ linux-4.4.13/kernel/signal.c 2016-06-22 21:55:08.062523867 +0200
  21153. @@ -14,6 +14,7 @@
  21154. #include <linux/export.h>
  21155. #include <linux/init.h>
  21156. #include <linux/sched.h>
  21157. +#include <linux/sched/rt.h>
  21158. #include <linux/fs.h>
  21159. #include <linux/tty.h>
  21160. #include <linux/binfmts.h>
  21161. @@ -352,13 +353,30 @@
  21162. return false;
  21163. }
  21164. +static inline struct sigqueue *get_task_cache(struct task_struct *t)
  21165. +{
  21166. + struct sigqueue *q = t->sigqueue_cache;
  21167. +
  21168. + if (cmpxchg(&t->sigqueue_cache, q, NULL) != q)
  21169. + return NULL;
  21170. + return q;
  21171. +}
  21172. +
  21173. +static inline int put_task_cache(struct task_struct *t, struct sigqueue *q)
  21174. +{
  21175. + if (cmpxchg(&t->sigqueue_cache, NULL, q) == NULL)
  21176. + return 0;
  21177. + return 1;
  21178. +}
  21179. +
  21180. /*
  21181. * allocate a new signal queue record
  21182. * - this may be called without locks if and only if t == current, otherwise an
  21183. * appropriate lock must be held to stop the target task from exiting
  21184. */
  21185. static struct sigqueue *
  21186. -__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit)
  21187. +__sigqueue_do_alloc(int sig, struct task_struct *t, gfp_t flags,
  21188. + int override_rlimit, int fromslab)
  21189. {
  21190. struct sigqueue *q = NULL;
  21191. struct user_struct *user;
  21192. @@ -375,7 +393,10 @@
  21193. if (override_rlimit ||
  21194. atomic_read(&user->sigpending) <=
  21195. task_rlimit(t, RLIMIT_SIGPENDING)) {
  21196. - q = kmem_cache_alloc(sigqueue_cachep, flags);
  21197. + if (!fromslab)
  21198. + q = get_task_cache(t);
  21199. + if (!q)
  21200. + q = kmem_cache_alloc(sigqueue_cachep, flags);
  21201. } else {
  21202. print_dropped_signal(sig);
  21203. }
  21204. @@ -392,6 +413,13 @@
  21205. return q;
  21206. }
  21207. +static struct sigqueue *
  21208. +__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags,
  21209. + int override_rlimit)
  21210. +{
  21211. + return __sigqueue_do_alloc(sig, t, flags, override_rlimit, 0);
  21212. +}
  21213. +
  21214. static void __sigqueue_free(struct sigqueue *q)
  21215. {
  21216. if (q->flags & SIGQUEUE_PREALLOC)
  21217. @@ -401,6 +429,21 @@
  21218. kmem_cache_free(sigqueue_cachep, q);
  21219. }
  21220. +static void sigqueue_free_current(struct sigqueue *q)
  21221. +{
  21222. + struct user_struct *up;
  21223. +
  21224. + if (q->flags & SIGQUEUE_PREALLOC)
  21225. + return;
  21226. +
  21227. + up = q->user;
  21228. + if (rt_prio(current->normal_prio) && !put_task_cache(current, q)) {
  21229. + atomic_dec(&up->sigpending);
  21230. + free_uid(up);
  21231. + } else
  21232. + __sigqueue_free(q);
  21233. +}
  21234. +
  21235. void flush_sigqueue(struct sigpending *queue)
  21236. {
  21237. struct sigqueue *q;
  21238. @@ -414,6 +457,21 @@
  21239. }
  21240. /*
  21241. + * Called from __exit_signal. Flush tsk->pending and
  21242. + * tsk->sigqueue_cache
  21243. + */
  21244. +void flush_task_sigqueue(struct task_struct *tsk)
  21245. +{
  21246. + struct sigqueue *q;
  21247. +
  21248. + flush_sigqueue(&tsk->pending);
  21249. +
  21250. + q = get_task_cache(tsk);
  21251. + if (q)
  21252. + kmem_cache_free(sigqueue_cachep, q);
  21253. +}
  21254. +
  21255. +/*
  21256. * Flush all pending signals for this kthread.
  21257. */
  21258. void flush_signals(struct task_struct *t)
  21259. @@ -525,7 +583,7 @@
  21260. still_pending:
  21261. list_del_init(&first->list);
  21262. copy_siginfo(info, &first->info);
  21263. - __sigqueue_free(first);
  21264. + sigqueue_free_current(first);
  21265. } else {
  21266. /*
  21267. * Ok, it wasn't in the queue. This must be
  21268. @@ -560,6 +618,8 @@
  21269. {
  21270. int signr;
  21271. + WARN_ON_ONCE(tsk != current);
  21272. +
  21273. /* We only dequeue private signals from ourselves, we don't let
  21274. * signalfd steal them
  21275. */
  21276. @@ -1156,8 +1216,8 @@
  21277. * We don't want to have recursive SIGSEGV's etc, for example,
  21278. * that is why we also clear SIGNAL_UNKILLABLE.
  21279. */
  21280. -int
  21281. -force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  21282. +static int
  21283. +do_force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  21284. {
  21285. unsigned long int flags;
  21286. int ret, blocked, ignored;
  21287. @@ -1182,6 +1242,39 @@
  21288. return ret;
  21289. }
  21290. +int force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  21291. +{
  21292. +/*
  21293. + * On some archs, PREEMPT_RT has to delay sending a signal from a trap
  21294. + * since it can not enable preemption, and the signal code's spin_locks
  21295. + * turn into mutexes. Instead, it must set TIF_NOTIFY_RESUME which will
  21296. + * send the signal on exit of the trap.
  21297. + */
  21298. +#ifdef ARCH_RT_DELAYS_SIGNAL_SEND
  21299. + if (in_atomic()) {
  21300. + if (WARN_ON_ONCE(t != current))
  21301. + return 0;
  21302. + if (WARN_ON_ONCE(t->forced_info.si_signo))
  21303. + return 0;
  21304. +
  21305. + if (is_si_special(info)) {
  21306. + WARN_ON_ONCE(info != SEND_SIG_PRIV);
  21307. + t->forced_info.si_signo = sig;
  21308. + t->forced_info.si_errno = 0;
  21309. + t->forced_info.si_code = SI_KERNEL;
  21310. + t->forced_info.si_pid = 0;
  21311. + t->forced_info.si_uid = 0;
  21312. + } else {
  21313. + t->forced_info = *info;
  21314. + }
  21315. +
  21316. + set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
  21317. + return 0;
  21318. + }
  21319. +#endif
  21320. + return do_force_sig_info(sig, info, t);
  21321. +}
  21322. +
  21323. /*
  21324. * Nuke all other threads in the group.
  21325. */
  21326. @@ -1216,12 +1309,12 @@
  21327. * Disable interrupts early to avoid deadlocks.
  21328. * See rcu_read_unlock() comment header for details.
  21329. */
  21330. - local_irq_save(*flags);
  21331. + local_irq_save_nort(*flags);
  21332. rcu_read_lock();
  21333. sighand = rcu_dereference(tsk->sighand);
  21334. if (unlikely(sighand == NULL)) {
  21335. rcu_read_unlock();
  21336. - local_irq_restore(*flags);
  21337. + local_irq_restore_nort(*flags);
  21338. break;
  21339. }
  21340. /*
  21341. @@ -1242,7 +1335,7 @@
  21342. }
  21343. spin_unlock(&sighand->siglock);
  21344. rcu_read_unlock();
  21345. - local_irq_restore(*flags);
  21346. + local_irq_restore_nort(*flags);
  21347. }
  21348. return sighand;
  21349. @@ -1485,7 +1578,8 @@
  21350. */
  21351. struct sigqueue *sigqueue_alloc(void)
  21352. {
  21353. - struct sigqueue *q = __sigqueue_alloc(-1, current, GFP_KERNEL, 0);
  21354. + /* Preallocated sigqueue objects always from the slabcache ! */
  21355. + struct sigqueue *q = __sigqueue_do_alloc(-1, current, GFP_KERNEL, 0, 1);
  21356. if (q)
  21357. q->flags |= SIGQUEUE_PREALLOC;
  21358. @@ -1846,15 +1940,7 @@
  21359. if (gstop_done && ptrace_reparented(current))
  21360. do_notify_parent_cldstop(current, false, why);
  21361. - /*
  21362. - * Don't want to allow preemption here, because
  21363. - * sys_ptrace() needs this task to be inactive.
  21364. - *
  21365. - * XXX: implement read_unlock_no_resched().
  21366. - */
  21367. - preempt_disable();
  21368. read_unlock(&tasklist_lock);
  21369. - preempt_enable_no_resched();
  21370. freezable_schedule();
  21371. } else {
  21372. /*
  21373. diff -Nur linux-4.4.13.orig/kernel/softirq.c linux-4.4.13/kernel/softirq.c
  21374. --- linux-4.4.13.orig/kernel/softirq.c 2016-06-08 03:14:51.000000000 +0200
  21375. +++ linux-4.4.13/kernel/softirq.c 2016-06-22 21:55:08.062523867 +0200
  21376. @@ -21,10 +21,12 @@
  21377. #include <linux/freezer.h>
  21378. #include <linux/kthread.h>
  21379. #include <linux/rcupdate.h>
  21380. +#include <linux/delay.h>
  21381. #include <linux/ftrace.h>
  21382. #include <linux/smp.h>
  21383. #include <linux/smpboot.h>
  21384. #include <linux/tick.h>
  21385. +#include <linux/locallock.h>
  21386. #include <linux/irq.h>
  21387. #define CREATE_TRACE_POINTS
  21388. @@ -56,12 +58,108 @@
  21389. static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
  21390. DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
  21391. +#ifdef CONFIG_PREEMPT_RT_FULL
  21392. +#define TIMER_SOFTIRQS ((1 << TIMER_SOFTIRQ) | (1 << HRTIMER_SOFTIRQ))
  21393. +DEFINE_PER_CPU(struct task_struct *, ktimer_softirqd);
  21394. +#endif
  21395. const char * const softirq_to_name[NR_SOFTIRQS] = {
  21396. "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
  21397. "TASKLET", "SCHED", "HRTIMER", "RCU"
  21398. };
  21399. +#ifdef CONFIG_NO_HZ_COMMON
  21400. +# ifdef CONFIG_PREEMPT_RT_FULL
  21401. +
  21402. +struct softirq_runner {
  21403. + struct task_struct *runner[NR_SOFTIRQS];
  21404. +};
  21405. +
  21406. +static DEFINE_PER_CPU(struct softirq_runner, softirq_runners);
  21407. +
  21408. +static inline void softirq_set_runner(unsigned int sirq)
  21409. +{
  21410. + struct softirq_runner *sr = this_cpu_ptr(&softirq_runners);
  21411. +
  21412. + sr->runner[sirq] = current;
  21413. +}
  21414. +
  21415. +static inline void softirq_clr_runner(unsigned int sirq)
  21416. +{
  21417. + struct softirq_runner *sr = this_cpu_ptr(&softirq_runners);
  21418. +
  21419. + sr->runner[sirq] = NULL;
  21420. +}
  21421. +
  21422. +/*
  21423. + * On preempt-rt a softirq running context might be blocked on a
  21424. + * lock. There might be no other runnable task on this CPU because the
  21425. + * lock owner runs on some other CPU. So we have to go into idle with
  21426. + * the pending bit set. Therefor we need to check this otherwise we
  21427. + * warn about false positives which confuses users and defeats the
  21428. + * whole purpose of this test.
  21429. + *
  21430. + * This code is called with interrupts disabled.
  21431. + */
  21432. +void softirq_check_pending_idle(void)
  21433. +{
  21434. + static int rate_limit;
  21435. + struct softirq_runner *sr = this_cpu_ptr(&softirq_runners);
  21436. + u32 warnpending;
  21437. + int i;
  21438. +
  21439. + if (rate_limit >= 10)
  21440. + return;
  21441. +
  21442. + warnpending = local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK;
  21443. + for (i = 0; i < NR_SOFTIRQS; i++) {
  21444. + struct task_struct *tsk = sr->runner[i];
  21445. +
  21446. + /*
  21447. + * The wakeup code in rtmutex.c wakes up the task
  21448. + * _before_ it sets pi_blocked_on to NULL under
  21449. + * tsk->pi_lock. So we need to check for both: state
  21450. + * and pi_blocked_on.
  21451. + */
  21452. + if (tsk) {
  21453. + raw_spin_lock(&tsk->pi_lock);
  21454. + if (tsk->pi_blocked_on || tsk->state == TASK_RUNNING) {
  21455. + /* Clear all bits pending in that task */
  21456. + warnpending &= ~(tsk->softirqs_raised);
  21457. + warnpending &= ~(1 << i);
  21458. + }
  21459. + raw_spin_unlock(&tsk->pi_lock);
  21460. + }
  21461. + }
  21462. +
  21463. + if (warnpending) {
  21464. + printk(KERN_ERR "NOHZ: local_softirq_pending %02x\n",
  21465. + warnpending);
  21466. + rate_limit++;
  21467. + }
  21468. +}
  21469. +# else
  21470. +/*
  21471. + * On !PREEMPT_RT we just printk rate limited:
  21472. + */
  21473. +void softirq_check_pending_idle(void)
  21474. +{
  21475. + static int rate_limit;
  21476. +
  21477. + if (rate_limit < 10 &&
  21478. + (local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK)) {
  21479. + printk(KERN_ERR "NOHZ: local_softirq_pending %02x\n",
  21480. + local_softirq_pending());
  21481. + rate_limit++;
  21482. + }
  21483. +}
  21484. +# endif
  21485. +
  21486. +#else /* !CONFIG_NO_HZ_COMMON */
  21487. +static inline void softirq_set_runner(unsigned int sirq) { }
  21488. +static inline void softirq_clr_runner(unsigned int sirq) { }
  21489. +#endif
  21490. +
  21491. /*
  21492. * we cannot loop indefinitely here to avoid userspace starvation,
  21493. * but we also don't want to introduce a worst case 1/HZ latency
  21494. @@ -77,6 +175,79 @@
  21495. wake_up_process(tsk);
  21496. }
  21497. +#ifdef CONFIG_PREEMPT_RT_FULL
  21498. +static void wakeup_timer_softirqd(void)
  21499. +{
  21500. + /* Interrupts are disabled: no need to stop preemption */
  21501. + struct task_struct *tsk = __this_cpu_read(ktimer_softirqd);
  21502. +
  21503. + if (tsk && tsk->state != TASK_RUNNING)
  21504. + wake_up_process(tsk);
  21505. +}
  21506. +#endif
  21507. +
  21508. +static void handle_softirq(unsigned int vec_nr)
  21509. +{
  21510. + struct softirq_action *h = softirq_vec + vec_nr;
  21511. + int prev_count;
  21512. +
  21513. + prev_count = preempt_count();
  21514. +
  21515. + kstat_incr_softirqs_this_cpu(vec_nr);
  21516. +
  21517. + trace_softirq_entry(vec_nr);
  21518. + h->action(h);
  21519. + trace_softirq_exit(vec_nr);
  21520. + if (unlikely(prev_count != preempt_count())) {
  21521. + pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
  21522. + vec_nr, softirq_to_name[vec_nr], h->action,
  21523. + prev_count, preempt_count());
  21524. + preempt_count_set(prev_count);
  21525. + }
  21526. +}
  21527. +
  21528. +#ifndef CONFIG_PREEMPT_RT_FULL
  21529. +static inline int ksoftirqd_softirq_pending(void)
  21530. +{
  21531. + return local_softirq_pending();
  21532. +}
  21533. +
  21534. +static void handle_pending_softirqs(u32 pending)
  21535. +{
  21536. + struct softirq_action *h = softirq_vec;
  21537. + int softirq_bit;
  21538. +
  21539. + local_irq_enable();
  21540. +
  21541. + h = softirq_vec;
  21542. +
  21543. + while ((softirq_bit = ffs(pending))) {
  21544. + unsigned int vec_nr;
  21545. +
  21546. + h += softirq_bit - 1;
  21547. + vec_nr = h - softirq_vec;
  21548. + handle_softirq(vec_nr);
  21549. +
  21550. + h++;
  21551. + pending >>= softirq_bit;
  21552. + }
  21553. +
  21554. + rcu_bh_qs();
  21555. + local_irq_disable();
  21556. +}
  21557. +
  21558. +static void run_ksoftirqd(unsigned int cpu)
  21559. +{
  21560. + local_irq_disable();
  21561. + if (ksoftirqd_softirq_pending()) {
  21562. + __do_softirq();
  21563. + local_irq_enable();
  21564. + cond_resched_rcu_qs();
  21565. + return;
  21566. + }
  21567. + local_irq_enable();
  21568. +}
  21569. +
  21570. /*
  21571. * preempt_count and SOFTIRQ_OFFSET usage:
  21572. * - preempt_count is changed by SOFTIRQ_OFFSET on entering or leaving
  21573. @@ -116,9 +287,9 @@
  21574. if (preempt_count() == cnt) {
  21575. #ifdef CONFIG_DEBUG_PREEMPT
  21576. - current->preempt_disable_ip = get_parent_ip(CALLER_ADDR1);
  21577. + current->preempt_disable_ip = get_lock_parent_ip();
  21578. #endif
  21579. - trace_preempt_off(CALLER_ADDR0, get_parent_ip(CALLER_ADDR1));
  21580. + trace_preempt_off(CALLER_ADDR0, get_lock_parent_ip());
  21581. }
  21582. }
  21583. EXPORT_SYMBOL(__local_bh_disable_ip);
  21584. @@ -232,10 +403,8 @@
  21585. unsigned long end = jiffies + MAX_SOFTIRQ_TIME;
  21586. unsigned long old_flags = current->flags;
  21587. int max_restart = MAX_SOFTIRQ_RESTART;
  21588. - struct softirq_action *h;
  21589. bool in_hardirq;
  21590. __u32 pending;
  21591. - int softirq_bit;
  21592. /*
  21593. * Mask out PF_MEMALLOC s current task context is borrowed for the
  21594. @@ -254,36 +423,7 @@
  21595. /* Reset the pending bitmask before enabling irqs */
  21596. set_softirq_pending(0);
  21597. - local_irq_enable();
  21598. -
  21599. - h = softirq_vec;
  21600. -
  21601. - while ((softirq_bit = ffs(pending))) {
  21602. - unsigned int vec_nr;
  21603. - int prev_count;
  21604. -
  21605. - h += softirq_bit - 1;
  21606. -
  21607. - vec_nr = h - softirq_vec;
  21608. - prev_count = preempt_count();
  21609. -
  21610. - kstat_incr_softirqs_this_cpu(vec_nr);
  21611. -
  21612. - trace_softirq_entry(vec_nr);
  21613. - h->action(h);
  21614. - trace_softirq_exit(vec_nr);
  21615. - if (unlikely(prev_count != preempt_count())) {
  21616. - pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
  21617. - vec_nr, softirq_to_name[vec_nr], h->action,
  21618. - prev_count, preempt_count());
  21619. - preempt_count_set(prev_count);
  21620. - }
  21621. - h++;
  21622. - pending >>= softirq_bit;
  21623. - }
  21624. -
  21625. - rcu_bh_qs();
  21626. - local_irq_disable();
  21627. + handle_pending_softirqs(pending);
  21628. pending = local_softirq_pending();
  21629. if (pending) {
  21630. @@ -320,6 +460,310 @@
  21631. }
  21632. /*
  21633. + * This function must run with irqs disabled!
  21634. + */
  21635. +void raise_softirq_irqoff(unsigned int nr)
  21636. +{
  21637. + __raise_softirq_irqoff(nr);
  21638. +
  21639. + /*
  21640. + * If we're in an interrupt or softirq, we're done
  21641. + * (this also catches softirq-disabled code). We will
  21642. + * actually run the softirq once we return from
  21643. + * the irq or softirq.
  21644. + *
  21645. + * Otherwise we wake up ksoftirqd to make sure we
  21646. + * schedule the softirq soon.
  21647. + */
  21648. + if (!in_interrupt())
  21649. + wakeup_softirqd();
  21650. +}
  21651. +
  21652. +void __raise_softirq_irqoff(unsigned int nr)
  21653. +{
  21654. + trace_softirq_raise(nr);
  21655. + or_softirq_pending(1UL << nr);
  21656. +}
  21657. +
  21658. +static inline void local_bh_disable_nort(void) { local_bh_disable(); }
  21659. +static inline void _local_bh_enable_nort(void) { _local_bh_enable(); }
  21660. +static void ksoftirqd_set_sched_params(unsigned int cpu) { }
  21661. +
  21662. +#else /* !PREEMPT_RT_FULL */
  21663. +
  21664. +/*
  21665. + * On RT we serialize softirq execution with a cpu local lock per softirq
  21666. + */
  21667. +static DEFINE_PER_CPU(struct local_irq_lock [NR_SOFTIRQS], local_softirq_locks);
  21668. +
  21669. +void __init softirq_early_init(void)
  21670. +{
  21671. + int i;
  21672. +
  21673. + for (i = 0; i < NR_SOFTIRQS; i++)
  21674. + local_irq_lock_init(local_softirq_locks[i]);
  21675. +}
  21676. +
  21677. +static void lock_softirq(int which)
  21678. +{
  21679. + local_lock(local_softirq_locks[which]);
  21680. +}
  21681. +
  21682. +static void unlock_softirq(int which)
  21683. +{
  21684. + local_unlock(local_softirq_locks[which]);
  21685. +}
  21686. +
  21687. +static void do_single_softirq(int which)
  21688. +{
  21689. + unsigned long old_flags = current->flags;
  21690. +
  21691. + current->flags &= ~PF_MEMALLOC;
  21692. + vtime_account_irq_enter(current);
  21693. + current->flags |= PF_IN_SOFTIRQ;
  21694. + lockdep_softirq_enter();
  21695. + local_irq_enable();
  21696. + handle_softirq(which);
  21697. + local_irq_disable();
  21698. + lockdep_softirq_exit();
  21699. + current->flags &= ~PF_IN_SOFTIRQ;
  21700. + vtime_account_irq_enter(current);
  21701. + tsk_restore_flags(current, old_flags, PF_MEMALLOC);
  21702. +}
  21703. +
  21704. +/*
  21705. + * Called with interrupts disabled. Process softirqs which were raised
  21706. + * in current context (or on behalf of ksoftirqd).
  21707. + */
  21708. +static void do_current_softirqs(void)
  21709. +{
  21710. + while (current->softirqs_raised) {
  21711. + int i = __ffs(current->softirqs_raised);
  21712. + unsigned int pending, mask = (1U << i);
  21713. +
  21714. + current->softirqs_raised &= ~mask;
  21715. + local_irq_enable();
  21716. +
  21717. + /*
  21718. + * If the lock is contended, we boost the owner to
  21719. + * process the softirq or leave the critical section
  21720. + * now.
  21721. + */
  21722. + lock_softirq(i);
  21723. + local_irq_disable();
  21724. + softirq_set_runner(i);
  21725. + /*
  21726. + * Check with the local_softirq_pending() bits,
  21727. + * whether we need to process this still or if someone
  21728. + * else took care of it.
  21729. + */
  21730. + pending = local_softirq_pending();
  21731. + if (pending & mask) {
  21732. + set_softirq_pending(pending & ~mask);
  21733. + do_single_softirq(i);
  21734. + }
  21735. + softirq_clr_runner(i);
  21736. + WARN_ON(current->softirq_nestcnt != 1);
  21737. + local_irq_enable();
  21738. + unlock_softirq(i);
  21739. + local_irq_disable();
  21740. + }
  21741. +}
  21742. +
  21743. +void __local_bh_disable(void)
  21744. +{
  21745. + if (++current->softirq_nestcnt == 1)
  21746. + migrate_disable();
  21747. +}
  21748. +EXPORT_SYMBOL(__local_bh_disable);
  21749. +
  21750. +void __local_bh_enable(void)
  21751. +{
  21752. + if (WARN_ON(current->softirq_nestcnt == 0))
  21753. + return;
  21754. +
  21755. + local_irq_disable();
  21756. + if (current->softirq_nestcnt == 1 && current->softirqs_raised)
  21757. + do_current_softirqs();
  21758. + local_irq_enable();
  21759. +
  21760. + if (--current->softirq_nestcnt == 0)
  21761. + migrate_enable();
  21762. +}
  21763. +EXPORT_SYMBOL(__local_bh_enable);
  21764. +
  21765. +void _local_bh_enable(void)
  21766. +{
  21767. + if (WARN_ON(current->softirq_nestcnt == 0))
  21768. + return;
  21769. + if (--current->softirq_nestcnt == 0)
  21770. + migrate_enable();
  21771. +}
  21772. +EXPORT_SYMBOL(_local_bh_enable);
  21773. +
  21774. +int in_serving_softirq(void)
  21775. +{
  21776. + return current->flags & PF_IN_SOFTIRQ;
  21777. +}
  21778. +EXPORT_SYMBOL(in_serving_softirq);
  21779. +
  21780. +/* Called with preemption disabled */
  21781. +static void run_ksoftirqd(unsigned int cpu)
  21782. +{
  21783. + local_irq_disable();
  21784. + current->softirq_nestcnt++;
  21785. +
  21786. + do_current_softirqs();
  21787. + current->softirq_nestcnt--;
  21788. + local_irq_enable();
  21789. + cond_resched_rcu_qs();
  21790. +}
  21791. +
  21792. +/*
  21793. + * Called from netif_rx_ni(). Preemption enabled, but migration
  21794. + * disabled. So the cpu can't go away under us.
  21795. + */
  21796. +void thread_do_softirq(void)
  21797. +{
  21798. + if (!in_serving_softirq() && current->softirqs_raised) {
  21799. + current->softirq_nestcnt++;
  21800. + do_current_softirqs();
  21801. + current->softirq_nestcnt--;
  21802. + }
  21803. +}
  21804. +
  21805. +static void do_raise_softirq_irqoff(unsigned int nr)
  21806. +{
  21807. + unsigned int mask;
  21808. +
  21809. + mask = 1UL << nr;
  21810. +
  21811. + trace_softirq_raise(nr);
  21812. + or_softirq_pending(mask);
  21813. +
  21814. + /*
  21815. + * If we are not in a hard interrupt and inside a bh disabled
  21816. + * region, we simply raise the flag on current. local_bh_enable()
  21817. + * will make sure that the softirq is executed. Otherwise we
  21818. + * delegate it to ksoftirqd.
  21819. + */
  21820. + if (!in_irq() && current->softirq_nestcnt)
  21821. + current->softirqs_raised |= mask;
  21822. + else if (!__this_cpu_read(ksoftirqd) || !__this_cpu_read(ktimer_softirqd))
  21823. + return;
  21824. +
  21825. + if (mask & TIMER_SOFTIRQS)
  21826. + __this_cpu_read(ktimer_softirqd)->softirqs_raised |= mask;
  21827. + else
  21828. + __this_cpu_read(ksoftirqd)->softirqs_raised |= mask;
  21829. +}
  21830. +
  21831. +static void wakeup_proper_softirq(unsigned int nr)
  21832. +{
  21833. + if ((1UL << nr) & TIMER_SOFTIRQS)
  21834. + wakeup_timer_softirqd();
  21835. + else
  21836. + wakeup_softirqd();
  21837. +}
  21838. +
  21839. +
  21840. +void __raise_softirq_irqoff(unsigned int nr)
  21841. +{
  21842. + do_raise_softirq_irqoff(nr);
  21843. + if (!in_irq() && !current->softirq_nestcnt)
  21844. + wakeup_proper_softirq(nr);
  21845. +}
  21846. +
  21847. +/*
  21848. + * Same as __raise_softirq_irqoff() but will process them in ksoftirqd
  21849. + */
  21850. +void __raise_softirq_irqoff_ksoft(unsigned int nr)
  21851. +{
  21852. + unsigned int mask;
  21853. +
  21854. + if (WARN_ON_ONCE(!__this_cpu_read(ksoftirqd) ||
  21855. + !__this_cpu_read(ktimer_softirqd)))
  21856. + return;
  21857. + mask = 1UL << nr;
  21858. +
  21859. + trace_softirq_raise(nr);
  21860. + or_softirq_pending(mask);
  21861. + if (mask & TIMER_SOFTIRQS)
  21862. + __this_cpu_read(ktimer_softirqd)->softirqs_raised |= mask;
  21863. + else
  21864. + __this_cpu_read(ksoftirqd)->softirqs_raised |= mask;
  21865. + wakeup_proper_softirq(nr);
  21866. +}
  21867. +
  21868. +/*
  21869. + * This function must run with irqs disabled!
  21870. + */
  21871. +void raise_softirq_irqoff(unsigned int nr)
  21872. +{
  21873. + do_raise_softirq_irqoff(nr);
  21874. +
  21875. + /*
  21876. + * If we're in an hard interrupt we let irq return code deal
  21877. + * with the wakeup of ksoftirqd.
  21878. + */
  21879. + if (in_irq())
  21880. + return;
  21881. + /*
  21882. + * If we are in thread context but outside of a bh disabled
  21883. + * region, we need to wake ksoftirqd as well.
  21884. + *
  21885. + * CHECKME: Some of the places which do that could be wrapped
  21886. + * into local_bh_disable/enable pairs. Though it's unclear
  21887. + * whether this is worth the effort. To find those places just
  21888. + * raise a WARN() if the condition is met.
  21889. + */
  21890. + if (!current->softirq_nestcnt)
  21891. + wakeup_proper_softirq(nr);
  21892. +}
  21893. +
  21894. +static inline int ksoftirqd_softirq_pending(void)
  21895. +{
  21896. + return current->softirqs_raised;
  21897. +}
  21898. +
  21899. +static inline void local_bh_disable_nort(void) { }
  21900. +static inline void _local_bh_enable_nort(void) { }
  21901. +
  21902. +static inline void ksoftirqd_set_sched_params(unsigned int cpu)
  21903. +{
  21904. + /* Take over all but timer pending softirqs when starting */
  21905. + local_irq_disable();
  21906. + current->softirqs_raised = local_softirq_pending() & ~TIMER_SOFTIRQS;
  21907. + local_irq_enable();
  21908. +}
  21909. +
  21910. +static inline void ktimer_softirqd_set_sched_params(unsigned int cpu)
  21911. +{
  21912. + struct sched_param param = { .sched_priority = 1 };
  21913. +
  21914. + sched_setscheduler(current, SCHED_FIFO, &param);
  21915. +
  21916. + /* Take over timer pending softirqs when starting */
  21917. + local_irq_disable();
  21918. + current->softirqs_raised = local_softirq_pending() & TIMER_SOFTIRQS;
  21919. + local_irq_enable();
  21920. +}
  21921. +
  21922. +static inline void ktimer_softirqd_clr_sched_params(unsigned int cpu,
  21923. + bool online)
  21924. +{
  21925. + struct sched_param param = { .sched_priority = 0 };
  21926. +
  21927. + sched_setscheduler(current, SCHED_NORMAL, &param);
  21928. +}
  21929. +
  21930. +static int ktimer_softirqd_should_run(unsigned int cpu)
  21931. +{
  21932. + return current->softirqs_raised;
  21933. +}
  21934. +
  21935. +#endif /* PREEMPT_RT_FULL */
  21936. +/*
  21937. * Enter an interrupt context.
  21938. */
  21939. void irq_enter(void)
  21940. @@ -330,9 +774,9 @@
  21941. * Prevent raise_softirq from needlessly waking up ksoftirqd
  21942. * here, as softirq will be serviced on return from interrupt.
  21943. */
  21944. - local_bh_disable();
  21945. + local_bh_disable_nort();
  21946. tick_irq_enter();
  21947. - _local_bh_enable();
  21948. + _local_bh_enable_nort();
  21949. }
  21950. __irq_enter();
  21951. @@ -340,6 +784,7 @@
  21952. static inline void invoke_softirq(void)
  21953. {
  21954. +#ifndef CONFIG_PREEMPT_RT_FULL
  21955. if (!force_irqthreads) {
  21956. #ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
  21957. /*
  21958. @@ -359,6 +804,18 @@
  21959. } else {
  21960. wakeup_softirqd();
  21961. }
  21962. +#else /* PREEMPT_RT_FULL */
  21963. + unsigned long flags;
  21964. +
  21965. + local_irq_save(flags);
  21966. + if (__this_cpu_read(ksoftirqd) &&
  21967. + __this_cpu_read(ksoftirqd)->softirqs_raised)
  21968. + wakeup_softirqd();
  21969. + if (__this_cpu_read(ktimer_softirqd) &&
  21970. + __this_cpu_read(ktimer_softirqd)->softirqs_raised)
  21971. + wakeup_timer_softirqd();
  21972. + local_irq_restore(flags);
  21973. +#endif
  21974. }
  21975. static inline void tick_irq_exit(void)
  21976. @@ -395,26 +852,6 @@
  21977. trace_hardirq_exit(); /* must be last! */
  21978. }
  21979. -/*
  21980. - * This function must run with irqs disabled!
  21981. - */
  21982. -inline void raise_softirq_irqoff(unsigned int nr)
  21983. -{
  21984. - __raise_softirq_irqoff(nr);
  21985. -
  21986. - /*
  21987. - * If we're in an interrupt or softirq, we're done
  21988. - * (this also catches softirq-disabled code). We will
  21989. - * actually run the softirq once we return from
  21990. - * the irq or softirq.
  21991. - *
  21992. - * Otherwise we wake up ksoftirqd to make sure we
  21993. - * schedule the softirq soon.
  21994. - */
  21995. - if (!in_interrupt())
  21996. - wakeup_softirqd();
  21997. -}
  21998. -
  21999. void raise_softirq(unsigned int nr)
  22000. {
  22001. unsigned long flags;
  22002. @@ -424,12 +861,6 @@
  22003. local_irq_restore(flags);
  22004. }
  22005. -void __raise_softirq_irqoff(unsigned int nr)
  22006. -{
  22007. - trace_softirq_raise(nr);
  22008. - or_softirq_pending(1UL << nr);
  22009. -}
  22010. -
  22011. void open_softirq(int nr, void (*action)(struct softirq_action *))
  22012. {
  22013. softirq_vec[nr].action = action;
  22014. @@ -446,15 +877,45 @@
  22015. static DEFINE_PER_CPU(struct tasklet_head, tasklet_vec);
  22016. static DEFINE_PER_CPU(struct tasklet_head, tasklet_hi_vec);
  22017. +static void inline
  22018. +__tasklet_common_schedule(struct tasklet_struct *t, struct tasklet_head *head, unsigned int nr)
  22019. +{
  22020. + if (tasklet_trylock(t)) {
  22021. +again:
  22022. + /* We may have been preempted before tasklet_trylock
  22023. + * and __tasklet_action may have already run.
  22024. + * So double check the sched bit while the takslet
  22025. + * is locked before adding it to the list.
  22026. + */
  22027. + if (test_bit(TASKLET_STATE_SCHED, &t->state)) {
  22028. + t->next = NULL;
  22029. + *head->tail = t;
  22030. + head->tail = &(t->next);
  22031. + raise_softirq_irqoff(nr);
  22032. + tasklet_unlock(t);
  22033. + } else {
  22034. + /* This is subtle. If we hit the corner case above
  22035. + * It is possible that we get preempted right here,
  22036. + * and another task has successfully called
  22037. + * tasklet_schedule(), then this function, and
  22038. + * failed on the trylock. Thus we must be sure
  22039. + * before releasing the tasklet lock, that the
  22040. + * SCHED_BIT is clear. Otherwise the tasklet
  22041. + * may get its SCHED_BIT set, but not added to the
  22042. + * list
  22043. + */
  22044. + if (!tasklet_tryunlock(t))
  22045. + goto again;
  22046. + }
  22047. + }
  22048. +}
  22049. +
  22050. void __tasklet_schedule(struct tasklet_struct *t)
  22051. {
  22052. unsigned long flags;
  22053. local_irq_save(flags);
  22054. - t->next = NULL;
  22055. - *__this_cpu_read(tasklet_vec.tail) = t;
  22056. - __this_cpu_write(tasklet_vec.tail, &(t->next));
  22057. - raise_softirq_irqoff(TASKLET_SOFTIRQ);
  22058. + __tasklet_common_schedule(t, this_cpu_ptr(&tasklet_vec), TASKLET_SOFTIRQ);
  22059. local_irq_restore(flags);
  22060. }
  22061. EXPORT_SYMBOL(__tasklet_schedule);
  22062. @@ -464,10 +925,7 @@
  22063. unsigned long flags;
  22064. local_irq_save(flags);
  22065. - t->next = NULL;
  22066. - *__this_cpu_read(tasklet_hi_vec.tail) = t;
  22067. - __this_cpu_write(tasklet_hi_vec.tail, &(t->next));
  22068. - raise_softirq_irqoff(HI_SOFTIRQ);
  22069. + __tasklet_common_schedule(t, this_cpu_ptr(&tasklet_hi_vec), HI_SOFTIRQ);
  22070. local_irq_restore(flags);
  22071. }
  22072. EXPORT_SYMBOL(__tasklet_hi_schedule);
  22073. @@ -476,82 +934,122 @@
  22074. {
  22075. BUG_ON(!irqs_disabled());
  22076. - t->next = __this_cpu_read(tasklet_hi_vec.head);
  22077. - __this_cpu_write(tasklet_hi_vec.head, t);
  22078. - __raise_softirq_irqoff(HI_SOFTIRQ);
  22079. + __tasklet_hi_schedule(t);
  22080. }
  22081. EXPORT_SYMBOL(__tasklet_hi_schedule_first);
  22082. -static void tasklet_action(struct softirq_action *a)
  22083. +void tasklet_enable(struct tasklet_struct *t)
  22084. {
  22085. - struct tasklet_struct *list;
  22086. + if (!atomic_dec_and_test(&t->count))
  22087. + return;
  22088. + if (test_and_clear_bit(TASKLET_STATE_PENDING, &t->state))
  22089. + tasklet_schedule(t);
  22090. +}
  22091. +EXPORT_SYMBOL(tasklet_enable);
  22092. - local_irq_disable();
  22093. - list = __this_cpu_read(tasklet_vec.head);
  22094. - __this_cpu_write(tasklet_vec.head, NULL);
  22095. - __this_cpu_write(tasklet_vec.tail, this_cpu_ptr(&tasklet_vec.head));
  22096. - local_irq_enable();
  22097. +static void __tasklet_action(struct softirq_action *a,
  22098. + struct tasklet_struct *list)
  22099. +{
  22100. + int loops = 1000000;
  22101. while (list) {
  22102. struct tasklet_struct *t = list;
  22103. list = list->next;
  22104. - if (tasklet_trylock(t)) {
  22105. - if (!atomic_read(&t->count)) {
  22106. - if (!test_and_clear_bit(TASKLET_STATE_SCHED,
  22107. - &t->state))
  22108. - BUG();
  22109. - t->func(t->data);
  22110. - tasklet_unlock(t);
  22111. - continue;
  22112. - }
  22113. - tasklet_unlock(t);
  22114. + /*
  22115. + * Should always succeed - after a tasklist got on the
  22116. + * list (after getting the SCHED bit set from 0 to 1),
  22117. + * nothing but the tasklet softirq it got queued to can
  22118. + * lock it:
  22119. + */
  22120. + if (!tasklet_trylock(t)) {
  22121. + WARN_ON(1);
  22122. + continue;
  22123. }
  22124. - local_irq_disable();
  22125. t->next = NULL;
  22126. - *__this_cpu_read(tasklet_vec.tail) = t;
  22127. - __this_cpu_write(tasklet_vec.tail, &(t->next));
  22128. - __raise_softirq_irqoff(TASKLET_SOFTIRQ);
  22129. - local_irq_enable();
  22130. +
  22131. + /*
  22132. + * If we cannot handle the tasklet because it's disabled,
  22133. + * mark it as pending. tasklet_enable() will later
  22134. + * re-schedule the tasklet.
  22135. + */
  22136. + if (unlikely(atomic_read(&t->count))) {
  22137. +out_disabled:
  22138. + /* implicit unlock: */
  22139. + wmb();
  22140. + t->state = TASKLET_STATEF_PENDING;
  22141. + continue;
  22142. + }
  22143. +
  22144. + /*
  22145. + * After this point on the tasklet might be rescheduled
  22146. + * on another CPU, but it can only be added to another
  22147. + * CPU's tasklet list if we unlock the tasklet (which we
  22148. + * dont do yet).
  22149. + */
  22150. + if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
  22151. + WARN_ON(1);
  22152. +
  22153. +again:
  22154. + t->func(t->data);
  22155. +
  22156. + /*
  22157. + * Try to unlock the tasklet. We must use cmpxchg, because
  22158. + * another CPU might have scheduled or disabled the tasklet.
  22159. + * We only allow the STATE_RUN -> 0 transition here.
  22160. + */
  22161. + while (!tasklet_tryunlock(t)) {
  22162. + /*
  22163. + * If it got disabled meanwhile, bail out:
  22164. + */
  22165. + if (atomic_read(&t->count))
  22166. + goto out_disabled;
  22167. + /*
  22168. + * If it got scheduled meanwhile, re-execute
  22169. + * the tasklet function:
  22170. + */
  22171. + if (test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
  22172. + goto again;
  22173. + if (!--loops) {
  22174. + printk("hm, tasklet state: %08lx\n", t->state);
  22175. + WARN_ON(1);
  22176. + tasklet_unlock(t);
  22177. + break;
  22178. + }
  22179. + }
  22180. }
  22181. }
  22182. +static void tasklet_action(struct softirq_action *a)
  22183. +{
  22184. + struct tasklet_struct *list;
  22185. +
  22186. + local_irq_disable();
  22187. +
  22188. + list = __this_cpu_read(tasklet_vec.head);
  22189. + __this_cpu_write(tasklet_vec.head, NULL);
  22190. + __this_cpu_write(tasklet_vec.tail, this_cpu_ptr(&tasklet_vec.head));
  22191. +
  22192. + local_irq_enable();
  22193. +
  22194. + __tasklet_action(a, list);
  22195. +}
  22196. +
  22197. static void tasklet_hi_action(struct softirq_action *a)
  22198. {
  22199. struct tasklet_struct *list;
  22200. local_irq_disable();
  22201. +
  22202. list = __this_cpu_read(tasklet_hi_vec.head);
  22203. __this_cpu_write(tasklet_hi_vec.head, NULL);
  22204. __this_cpu_write(tasklet_hi_vec.tail, this_cpu_ptr(&tasklet_hi_vec.head));
  22205. - local_irq_enable();
  22206. - while (list) {
  22207. - struct tasklet_struct *t = list;
  22208. -
  22209. - list = list->next;
  22210. -
  22211. - if (tasklet_trylock(t)) {
  22212. - if (!atomic_read(&t->count)) {
  22213. - if (!test_and_clear_bit(TASKLET_STATE_SCHED,
  22214. - &t->state))
  22215. - BUG();
  22216. - t->func(t->data);
  22217. - tasklet_unlock(t);
  22218. - continue;
  22219. - }
  22220. - tasklet_unlock(t);
  22221. - }
  22222. + local_irq_enable();
  22223. - local_irq_disable();
  22224. - t->next = NULL;
  22225. - *__this_cpu_read(tasklet_hi_vec.tail) = t;
  22226. - __this_cpu_write(tasklet_hi_vec.tail, &(t->next));
  22227. - __raise_softirq_irqoff(HI_SOFTIRQ);
  22228. - local_irq_enable();
  22229. - }
  22230. + __tasklet_action(a, list);
  22231. }
  22232. void tasklet_init(struct tasklet_struct *t,
  22233. @@ -572,7 +1070,7 @@
  22234. while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
  22235. do {
  22236. - yield();
  22237. + msleep(1);
  22238. } while (test_bit(TASKLET_STATE_SCHED, &t->state));
  22239. }
  22240. tasklet_unlock_wait(t);
  22241. @@ -646,25 +1144,26 @@
  22242. open_softirq(HI_SOFTIRQ, tasklet_hi_action);
  22243. }
  22244. -static int ksoftirqd_should_run(unsigned int cpu)
  22245. -{
  22246. - return local_softirq_pending();
  22247. -}
  22248. -
  22249. -static void run_ksoftirqd(unsigned int cpu)
  22250. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  22251. +void tasklet_unlock_wait(struct tasklet_struct *t)
  22252. {
  22253. - local_irq_disable();
  22254. - if (local_softirq_pending()) {
  22255. + while (test_bit(TASKLET_STATE_RUN, &(t)->state)) {
  22256. /*
  22257. - * We can safely run softirq on inline stack, as we are not deep
  22258. - * in the task stack here.
  22259. + * Hack for now to avoid this busy-loop:
  22260. */
  22261. - __do_softirq();
  22262. - local_irq_enable();
  22263. - cond_resched_rcu_qs();
  22264. - return;
  22265. +#ifdef CONFIG_PREEMPT_RT_FULL
  22266. + msleep(1);
  22267. +#else
  22268. + barrier();
  22269. +#endif
  22270. }
  22271. - local_irq_enable();
  22272. +}
  22273. +EXPORT_SYMBOL(tasklet_unlock_wait);
  22274. +#endif
  22275. +
  22276. +static int ksoftirqd_should_run(unsigned int cpu)
  22277. +{
  22278. + return ksoftirqd_softirq_pending();
  22279. }
  22280. #ifdef CONFIG_HOTPLUG_CPU
  22281. @@ -746,16 +1245,31 @@
  22282. static struct smp_hotplug_thread softirq_threads = {
  22283. .store = &ksoftirqd,
  22284. + .setup = ksoftirqd_set_sched_params,
  22285. .thread_should_run = ksoftirqd_should_run,
  22286. .thread_fn = run_ksoftirqd,
  22287. .thread_comm = "ksoftirqd/%u",
  22288. };
  22289. +#ifdef CONFIG_PREEMPT_RT_FULL
  22290. +static struct smp_hotplug_thread softirq_timer_threads = {
  22291. + .store = &ktimer_softirqd,
  22292. + .setup = ktimer_softirqd_set_sched_params,
  22293. + .cleanup = ktimer_softirqd_clr_sched_params,
  22294. + .thread_should_run = ktimer_softirqd_should_run,
  22295. + .thread_fn = run_ksoftirqd,
  22296. + .thread_comm = "ktimersoftd/%u",
  22297. +};
  22298. +#endif
  22299. +
  22300. static __init int spawn_ksoftirqd(void)
  22301. {
  22302. register_cpu_notifier(&cpu_nfb);
  22303. BUG_ON(smpboot_register_percpu_thread(&softirq_threads));
  22304. +#ifdef CONFIG_PREEMPT_RT_FULL
  22305. + BUG_ON(smpboot_register_percpu_thread(&softirq_timer_threads));
  22306. +#endif
  22307. return 0;
  22308. }
  22309. diff -Nur linux-4.4.13.orig/kernel/stop_machine.c linux-4.4.13/kernel/stop_machine.c
  22310. --- linux-4.4.13.orig/kernel/stop_machine.c 2016-06-08 03:14:51.000000000 +0200
  22311. +++ linux-4.4.13/kernel/stop_machine.c 2016-06-22 21:55:08.062523867 +0200
  22312. @@ -37,7 +37,7 @@
  22313. struct cpu_stopper {
  22314. struct task_struct *thread;
  22315. - spinlock_t lock;
  22316. + raw_spinlock_t lock;
  22317. bool enabled; /* is this stopper enabled? */
  22318. struct list_head works; /* list of pending works */
  22319. @@ -86,12 +86,12 @@
  22320. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  22321. unsigned long flags;
  22322. - spin_lock_irqsave(&stopper->lock, flags);
  22323. + raw_spin_lock_irqsave(&stopper->lock, flags);
  22324. if (stopper->enabled)
  22325. __cpu_stop_queue_work(stopper, work);
  22326. else
  22327. cpu_stop_signal_done(work->done, false);
  22328. - spin_unlock_irqrestore(&stopper->lock, flags);
  22329. + raw_spin_unlock_irqrestore(&stopper->lock, flags);
  22330. }
  22331. /**
  22332. @@ -224,8 +224,8 @@
  22333. int err;
  22334. lg_double_lock(&stop_cpus_lock, cpu1, cpu2);
  22335. - spin_lock_irq(&stopper1->lock);
  22336. - spin_lock_nested(&stopper2->lock, SINGLE_DEPTH_NESTING);
  22337. + raw_spin_lock_irq(&stopper1->lock);
  22338. + raw_spin_lock_nested(&stopper2->lock, SINGLE_DEPTH_NESTING);
  22339. err = -ENOENT;
  22340. if (!stopper1->enabled || !stopper2->enabled)
  22341. @@ -235,8 +235,8 @@
  22342. __cpu_stop_queue_work(stopper1, work1);
  22343. __cpu_stop_queue_work(stopper2, work2);
  22344. unlock:
  22345. - spin_unlock(&stopper2->lock);
  22346. - spin_unlock_irq(&stopper1->lock);
  22347. + raw_spin_unlock(&stopper2->lock);
  22348. + raw_spin_unlock_irq(&stopper1->lock);
  22349. lg_double_unlock(&stop_cpus_lock, cpu1, cpu2);
  22350. return err;
  22351. @@ -258,7 +258,7 @@
  22352. struct cpu_stop_work work1, work2;
  22353. struct multi_stop_data msdata;
  22354. - preempt_disable();
  22355. + preempt_disable_nort();
  22356. msdata = (struct multi_stop_data){
  22357. .fn = fn,
  22358. .data = arg,
  22359. @@ -278,11 +278,11 @@
  22360. if (cpu1 > cpu2)
  22361. swap(cpu1, cpu2);
  22362. if (cpu_stop_queue_two_works(cpu1, &work1, cpu2, &work2)) {
  22363. - preempt_enable();
  22364. + preempt_enable_nort();
  22365. return -ENOENT;
  22366. }
  22367. - preempt_enable();
  22368. + preempt_enable_nort();
  22369. wait_for_completion(&done.completion);
  22370. @@ -315,17 +315,20 @@
  22371. static void queue_stop_cpus_work(const struct cpumask *cpumask,
  22372. cpu_stop_fn_t fn, void *arg,
  22373. - struct cpu_stop_done *done)
  22374. + struct cpu_stop_done *done, bool inactive)
  22375. {
  22376. struct cpu_stop_work *work;
  22377. unsigned int cpu;
  22378. /*
  22379. - * Disable preemption while queueing to avoid getting
  22380. - * preempted by a stopper which might wait for other stoppers
  22381. - * to enter @fn which can lead to deadlock.
  22382. + * Make sure that all work is queued on all cpus before
  22383. + * any of the cpus can execute it.
  22384. */
  22385. - lg_global_lock(&stop_cpus_lock);
  22386. + if (!inactive)
  22387. + lg_global_lock(&stop_cpus_lock);
  22388. + else
  22389. + lg_global_trylock_relax(&stop_cpus_lock);
  22390. +
  22391. for_each_cpu(cpu, cpumask) {
  22392. work = &per_cpu(cpu_stopper.stop_work, cpu);
  22393. work->fn = fn;
  22394. @@ -342,7 +345,7 @@
  22395. struct cpu_stop_done done;
  22396. cpu_stop_init_done(&done, cpumask_weight(cpumask));
  22397. - queue_stop_cpus_work(cpumask, fn, arg, &done);
  22398. + queue_stop_cpus_work(cpumask, fn, arg, &done, false);
  22399. wait_for_completion(&done.completion);
  22400. return done.executed ? done.ret : -ENOENT;
  22401. }
  22402. @@ -422,9 +425,9 @@
  22403. unsigned long flags;
  22404. int run;
  22405. - spin_lock_irqsave(&stopper->lock, flags);
  22406. + raw_spin_lock_irqsave(&stopper->lock, flags);
  22407. run = !list_empty(&stopper->works);
  22408. - spin_unlock_irqrestore(&stopper->lock, flags);
  22409. + raw_spin_unlock_irqrestore(&stopper->lock, flags);
  22410. return run;
  22411. }
  22412. @@ -436,13 +439,13 @@
  22413. repeat:
  22414. work = NULL;
  22415. - spin_lock_irq(&stopper->lock);
  22416. + raw_spin_lock_irq(&stopper->lock);
  22417. if (!list_empty(&stopper->works)) {
  22418. work = list_first_entry(&stopper->works,
  22419. struct cpu_stop_work, list);
  22420. list_del_init(&work->list);
  22421. }
  22422. - spin_unlock_irq(&stopper->lock);
  22423. + raw_spin_unlock_irq(&stopper->lock);
  22424. if (work) {
  22425. cpu_stop_fn_t fn = work->fn;
  22426. @@ -450,6 +453,16 @@
  22427. struct cpu_stop_done *done = work->done;
  22428. char ksym_buf[KSYM_NAME_LEN] __maybe_unused;
  22429. + /*
  22430. + * Wait until the stopper finished scheduling on all
  22431. + * cpus
  22432. + */
  22433. + lg_global_lock(&stop_cpus_lock);
  22434. + /*
  22435. + * Let other cpu threads continue as well
  22436. + */
  22437. + lg_global_unlock(&stop_cpus_lock);
  22438. +
  22439. /* cpu stop callbacks are not allowed to sleep */
  22440. preempt_disable();
  22441. @@ -520,10 +533,12 @@
  22442. for_each_possible_cpu(cpu) {
  22443. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  22444. - spin_lock_init(&stopper->lock);
  22445. + raw_spin_lock_init(&stopper->lock);
  22446. INIT_LIST_HEAD(&stopper->works);
  22447. }
  22448. + lg_lock_init(&stop_cpus_lock, "stop_cpus_lock");
  22449. +
  22450. BUG_ON(smpboot_register_percpu_thread(&cpu_stop_threads));
  22451. stop_machine_unpark(raw_smp_processor_id());
  22452. stop_machine_initialized = true;
  22453. @@ -620,7 +635,7 @@
  22454. set_state(&msdata, MULTI_STOP_PREPARE);
  22455. cpu_stop_init_done(&done, num_active_cpus());
  22456. queue_stop_cpus_work(cpu_active_mask, multi_cpu_stop, &msdata,
  22457. - &done);
  22458. + &done, true);
  22459. ret = multi_cpu_stop(&msdata);
  22460. /* Busy wait for completion. */
  22461. diff -Nur linux-4.4.13.orig/kernel/time/hrtimer.c linux-4.4.13/kernel/time/hrtimer.c
  22462. --- linux-4.4.13.orig/kernel/time/hrtimer.c 2016-06-08 03:14:51.000000000 +0200
  22463. +++ linux-4.4.13/kernel/time/hrtimer.c 2016-06-22 21:55:08.062523867 +0200
  22464. @@ -48,11 +48,13 @@
  22465. #include <linux/sched/rt.h>
  22466. #include <linux/sched/deadline.h>
  22467. #include <linux/timer.h>
  22468. +#include <linux/kthread.h>
  22469. #include <linux/freezer.h>
  22470. #include <asm/uaccess.h>
  22471. #include <trace/events/timer.h>
  22472. +#include <trace/events/hist.h>
  22473. #include "tick-internal.h"
  22474. @@ -712,6 +714,44 @@
  22475. static DECLARE_WORK(hrtimer_work, clock_was_set_work);
  22476. +#ifdef CONFIG_PREEMPT_RT_FULL
  22477. +/*
  22478. + * RT can not call schedule_work from real interrupt context.
  22479. + * Need to make a thread to do the real work.
  22480. + */
  22481. +static struct task_struct *clock_set_delay_thread;
  22482. +static bool do_clock_set_delay;
  22483. +
  22484. +static int run_clock_set_delay(void *ignore)
  22485. +{
  22486. + while (!kthread_should_stop()) {
  22487. + set_current_state(TASK_INTERRUPTIBLE);
  22488. + if (do_clock_set_delay) {
  22489. + do_clock_set_delay = false;
  22490. + schedule_work(&hrtimer_work);
  22491. + }
  22492. + schedule();
  22493. + }
  22494. + __set_current_state(TASK_RUNNING);
  22495. + return 0;
  22496. +}
  22497. +
  22498. +void clock_was_set_delayed(void)
  22499. +{
  22500. + do_clock_set_delay = true;
  22501. + /* Make visible before waking up process */
  22502. + smp_wmb();
  22503. + wake_up_process(clock_set_delay_thread);
  22504. +}
  22505. +
  22506. +static __init int create_clock_set_delay_thread(void)
  22507. +{
  22508. + clock_set_delay_thread = kthread_run(run_clock_set_delay, NULL, "kclksetdelayd");
  22509. + BUG_ON(!clock_set_delay_thread);
  22510. + return 0;
  22511. +}
  22512. +early_initcall(create_clock_set_delay_thread);
  22513. +#else /* PREEMPT_RT_FULL */
  22514. /*
  22515. * Called from timekeeping and resume code to reprogramm the hrtimer
  22516. * interrupt device on all cpus.
  22517. @@ -720,6 +760,7 @@
  22518. {
  22519. schedule_work(&hrtimer_work);
  22520. }
  22521. +#endif
  22522. #else
  22523. @@ -729,11 +770,8 @@
  22524. static inline void hrtimer_switch_to_hres(void) { }
  22525. static inline void
  22526. hrtimer_force_reprogram(struct hrtimer_cpu_base *base, int skip_equal) { }
  22527. -static inline int hrtimer_reprogram(struct hrtimer *timer,
  22528. - struct hrtimer_clock_base *base)
  22529. -{
  22530. - return 0;
  22531. -}
  22532. +static inline void hrtimer_reprogram(struct hrtimer *timer,
  22533. + struct hrtimer_clock_base *base) { }
  22534. static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { }
  22535. static inline void retrigger_next_event(void *arg) { }
  22536. @@ -865,6 +903,32 @@
  22537. }
  22538. EXPORT_SYMBOL_GPL(hrtimer_forward);
  22539. +#ifdef CONFIG_PREEMPT_RT_BASE
  22540. +# define wake_up_timer_waiters(b) wake_up(&(b)->wait)
  22541. +
  22542. +/**
  22543. + * hrtimer_wait_for_timer - Wait for a running timer
  22544. + *
  22545. + * @timer: timer to wait for
  22546. + *
  22547. + * The function waits in case the timers callback function is
  22548. + * currently executed on the waitqueue of the timer base. The
  22549. + * waitqueue is woken up after the timer callback function has
  22550. + * finished execution.
  22551. + */
  22552. +void hrtimer_wait_for_timer(const struct hrtimer *timer)
  22553. +{
  22554. + struct hrtimer_clock_base *base = timer->base;
  22555. +
  22556. + if (base && base->cpu_base && !timer->irqsafe)
  22557. + wait_event(base->cpu_base->wait,
  22558. + !(hrtimer_callback_running(timer)));
  22559. +}
  22560. +
  22561. +#else
  22562. +# define wake_up_timer_waiters(b) do { } while (0)
  22563. +#endif
  22564. +
  22565. /*
  22566. * enqueue_hrtimer - internal function to (re)start a timer
  22567. *
  22568. @@ -906,6 +970,11 @@
  22569. if (!(state & HRTIMER_STATE_ENQUEUED))
  22570. return;
  22571. + if (unlikely(!list_empty(&timer->cb_entry))) {
  22572. + list_del_init(&timer->cb_entry);
  22573. + return;
  22574. + }
  22575. +
  22576. if (!timerqueue_del(&base->active, &timer->node))
  22577. cpu_base->active_bases &= ~(1 << base->index);
  22578. @@ -1001,7 +1070,16 @@
  22579. new_base = switch_hrtimer_base(timer, base, mode & HRTIMER_MODE_PINNED);
  22580. timer_stats_hrtimer_set_start_info(timer);
  22581. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  22582. + {
  22583. + ktime_t now = new_base->get_time();
  22584. + if (ktime_to_ns(tim) < ktime_to_ns(now))
  22585. + timer->praecox = now;
  22586. + else
  22587. + timer->praecox = ktime_set(0, 0);
  22588. + }
  22589. +#endif
  22590. leftmost = enqueue_hrtimer(timer, new_base);
  22591. if (!leftmost)
  22592. goto unlock;
  22593. @@ -1073,7 +1151,7 @@
  22594. if (ret >= 0)
  22595. return ret;
  22596. - cpu_relax();
  22597. + hrtimer_wait_for_timer(timer);
  22598. }
  22599. }
  22600. EXPORT_SYMBOL_GPL(hrtimer_cancel);
  22601. @@ -1137,6 +1215,7 @@
  22602. base = hrtimer_clockid_to_base(clock_id);
  22603. timer->base = &cpu_base->clock_base[base];
  22604. + INIT_LIST_HEAD(&timer->cb_entry);
  22605. timerqueue_init(&timer->node);
  22606. #ifdef CONFIG_TIMER_STATS
  22607. @@ -1177,6 +1256,7 @@
  22608. seq = raw_read_seqcount_begin(&cpu_base->seq);
  22609. if (timer->state != HRTIMER_STATE_INACTIVE ||
  22610. + cpu_base->running_soft == timer ||
  22611. cpu_base->running == timer)
  22612. return true;
  22613. @@ -1275,10 +1355,112 @@
  22614. cpu_base->running = NULL;
  22615. }
  22616. +#ifdef CONFIG_PREEMPT_RT_BASE
  22617. +static void hrtimer_rt_reprogram(int restart, struct hrtimer *timer,
  22618. + struct hrtimer_clock_base *base)
  22619. +{
  22620. + int leftmost;
  22621. +
  22622. + if (restart != HRTIMER_NORESTART &&
  22623. + !(timer->state & HRTIMER_STATE_ENQUEUED)) {
  22624. +
  22625. + leftmost = enqueue_hrtimer(timer, base);
  22626. + if (!leftmost)
  22627. + return;
  22628. +#ifdef CONFIG_HIGH_RES_TIMERS
  22629. + if (!hrtimer_is_hres_active(timer)) {
  22630. + /*
  22631. + * Kick to reschedule the next tick to handle the new timer
  22632. + * on dynticks target.
  22633. + */
  22634. + if (base->cpu_base->nohz_active)
  22635. + wake_up_nohz_cpu(base->cpu_base->cpu);
  22636. + } else {
  22637. +
  22638. + hrtimer_reprogram(timer, base);
  22639. + }
  22640. +#endif
  22641. + }
  22642. +}
  22643. +
  22644. +/*
  22645. + * The changes in mainline which removed the callback modes from
  22646. + * hrtimer are not yet working with -rt. The non wakeup_process()
  22647. + * based callbacks which involve sleeping locks need to be treated
  22648. + * seperately.
  22649. + */
  22650. +static void hrtimer_rt_run_pending(void)
  22651. +{
  22652. + enum hrtimer_restart (*fn)(struct hrtimer *);
  22653. + struct hrtimer_cpu_base *cpu_base;
  22654. + struct hrtimer_clock_base *base;
  22655. + struct hrtimer *timer;
  22656. + int index, restart;
  22657. +
  22658. + local_irq_disable();
  22659. + cpu_base = &per_cpu(hrtimer_bases, smp_processor_id());
  22660. +
  22661. + raw_spin_lock(&cpu_base->lock);
  22662. +
  22663. + for (index = 0; index < HRTIMER_MAX_CLOCK_BASES; index++) {
  22664. + base = &cpu_base->clock_base[index];
  22665. +
  22666. + while (!list_empty(&base->expired)) {
  22667. + timer = list_first_entry(&base->expired,
  22668. + struct hrtimer, cb_entry);
  22669. +
  22670. + /*
  22671. + * Same as the above __run_hrtimer function
  22672. + * just we run with interrupts enabled.
  22673. + */
  22674. + debug_deactivate(timer);
  22675. + cpu_base->running_soft = timer;
  22676. + raw_write_seqcount_barrier(&cpu_base->seq);
  22677. +
  22678. + __remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE, 0);
  22679. + timer_stats_account_hrtimer(timer);
  22680. + fn = timer->function;
  22681. +
  22682. + raw_spin_unlock_irq(&cpu_base->lock);
  22683. + restart = fn(timer);
  22684. + raw_spin_lock_irq(&cpu_base->lock);
  22685. +
  22686. + hrtimer_rt_reprogram(restart, timer, base);
  22687. + raw_write_seqcount_barrier(&cpu_base->seq);
  22688. +
  22689. + WARN_ON_ONCE(cpu_base->running_soft != timer);
  22690. + cpu_base->running_soft = NULL;
  22691. + }
  22692. + }
  22693. +
  22694. + raw_spin_unlock_irq(&cpu_base->lock);
  22695. +
  22696. + wake_up_timer_waiters(cpu_base);
  22697. +}
  22698. +
  22699. +static int hrtimer_rt_defer(struct hrtimer *timer)
  22700. +{
  22701. + if (timer->irqsafe)
  22702. + return 0;
  22703. +
  22704. + __remove_hrtimer(timer, timer->base, timer->state, 0);
  22705. + list_add_tail(&timer->cb_entry, &timer->base->expired);
  22706. + return 1;
  22707. +}
  22708. +
  22709. +#else
  22710. +
  22711. +static inline int hrtimer_rt_defer(struct hrtimer *timer) { return 0; }
  22712. +
  22713. +#endif
  22714. +
  22715. +static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer);
  22716. +
  22717. static void __hrtimer_run_queues(struct hrtimer_cpu_base *cpu_base, ktime_t now)
  22718. {
  22719. struct hrtimer_clock_base *base = cpu_base->clock_base;
  22720. unsigned int active = cpu_base->active_bases;
  22721. + int raise = 0;
  22722. for (; active; base++, active >>= 1) {
  22723. struct timerqueue_node *node;
  22724. @@ -1294,6 +1476,15 @@
  22725. timer = container_of(node, struct hrtimer, node);
  22726. + trace_hrtimer_interrupt(raw_smp_processor_id(),
  22727. + ktime_to_ns(ktime_sub(ktime_to_ns(timer->praecox) ?
  22728. + timer->praecox : hrtimer_get_expires(timer),
  22729. + basenow)),
  22730. + current,
  22731. + timer->function == hrtimer_wakeup ?
  22732. + container_of(timer, struct hrtimer_sleeper,
  22733. + timer)->task : NULL);
  22734. +
  22735. /*
  22736. * The immediate goal for using the softexpires is
  22737. * minimizing wakeups, not running timers at the
  22738. @@ -1309,9 +1500,14 @@
  22739. if (basenow.tv64 < hrtimer_get_softexpires_tv64(timer))
  22740. break;
  22741. - __run_hrtimer(cpu_base, base, timer, &basenow);
  22742. + if (!hrtimer_rt_defer(timer))
  22743. + __run_hrtimer(cpu_base, base, timer, &basenow);
  22744. + else
  22745. + raise = 1;
  22746. }
  22747. }
  22748. + if (raise)
  22749. + raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  22750. }
  22751. #ifdef CONFIG_HIGH_RES_TIMERS
  22752. @@ -1474,16 +1670,18 @@
  22753. void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task)
  22754. {
  22755. sl->timer.function = hrtimer_wakeup;
  22756. + sl->timer.irqsafe = 1;
  22757. sl->task = task;
  22758. }
  22759. EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
  22760. -static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode)
  22761. +static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode,
  22762. + unsigned long state)
  22763. {
  22764. hrtimer_init_sleeper(t, current);
  22765. do {
  22766. - set_current_state(TASK_INTERRUPTIBLE);
  22767. + set_current_state(state);
  22768. hrtimer_start_expires(&t->timer, mode);
  22769. if (likely(t->task))
  22770. @@ -1525,7 +1723,8 @@
  22771. HRTIMER_MODE_ABS);
  22772. hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires);
  22773. - if (do_nanosleep(&t, HRTIMER_MODE_ABS))
  22774. + /* cpu_chill() does not care about restart state. */
  22775. + if (do_nanosleep(&t, HRTIMER_MODE_ABS, TASK_INTERRUPTIBLE))
  22776. goto out;
  22777. rmtp = restart->nanosleep.rmtp;
  22778. @@ -1542,8 +1741,10 @@
  22779. return ret;
  22780. }
  22781. -long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  22782. - const enum hrtimer_mode mode, const clockid_t clockid)
  22783. +static long
  22784. +__hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  22785. + const enum hrtimer_mode mode, const clockid_t clockid,
  22786. + unsigned long state)
  22787. {
  22788. struct restart_block *restart;
  22789. struct hrtimer_sleeper t;
  22790. @@ -1556,7 +1757,7 @@
  22791. hrtimer_init_on_stack(&t.timer, clockid, mode);
  22792. hrtimer_set_expires_range_ns(&t.timer, timespec_to_ktime(*rqtp), slack);
  22793. - if (do_nanosleep(&t, mode))
  22794. + if (do_nanosleep(&t, mode, state))
  22795. goto out;
  22796. /* Absolute timers do not update the rmtp value and restart: */
  22797. @@ -1583,6 +1784,12 @@
  22798. return ret;
  22799. }
  22800. +long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  22801. + const enum hrtimer_mode mode, const clockid_t clockid)
  22802. +{
  22803. + return __hrtimer_nanosleep(rqtp, rmtp, mode, clockid, TASK_INTERRUPTIBLE);
  22804. +}
  22805. +
  22806. SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp,
  22807. struct timespec __user *, rmtp)
  22808. {
  22809. @@ -1597,6 +1804,26 @@
  22810. return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
  22811. }
  22812. +#ifdef CONFIG_PREEMPT_RT_FULL
  22813. +/*
  22814. + * Sleep for 1 ms in hope whoever holds what we want will let it go.
  22815. + */
  22816. +void cpu_chill(void)
  22817. +{
  22818. + struct timespec tu = {
  22819. + .tv_nsec = NSEC_PER_MSEC,
  22820. + };
  22821. + unsigned int freeze_flag = current->flags & PF_NOFREEZE;
  22822. +
  22823. + current->flags |= PF_NOFREEZE;
  22824. + __hrtimer_nanosleep(&tu, NULL, HRTIMER_MODE_REL, CLOCK_MONOTONIC,
  22825. + TASK_UNINTERRUPTIBLE);
  22826. + if (!freeze_flag)
  22827. + current->flags &= ~PF_NOFREEZE;
  22828. +}
  22829. +EXPORT_SYMBOL(cpu_chill);
  22830. +#endif
  22831. +
  22832. /*
  22833. * Functions related to boot-time initialization:
  22834. */
  22835. @@ -1608,10 +1835,14 @@
  22836. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
  22837. cpu_base->clock_base[i].cpu_base = cpu_base;
  22838. timerqueue_init_head(&cpu_base->clock_base[i].active);
  22839. + INIT_LIST_HEAD(&cpu_base->clock_base[i].expired);
  22840. }
  22841. cpu_base->cpu = cpu;
  22842. hrtimer_init_hres(cpu_base);
  22843. +#ifdef CONFIG_PREEMPT_RT_BASE
  22844. + init_waitqueue_head(&cpu_base->wait);
  22845. +#endif
  22846. }
  22847. #ifdef CONFIG_HOTPLUG_CPU
  22848. @@ -1709,11 +1940,21 @@
  22849. .notifier_call = hrtimer_cpu_notify,
  22850. };
  22851. +#ifdef CONFIG_PREEMPT_RT_BASE
  22852. +static void run_hrtimer_softirq(struct softirq_action *h)
  22853. +{
  22854. + hrtimer_rt_run_pending();
  22855. +}
  22856. +#endif
  22857. +
  22858. void __init hrtimers_init(void)
  22859. {
  22860. hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE,
  22861. (void *)(long)smp_processor_id());
  22862. register_cpu_notifier(&hrtimers_nb);
  22863. +#ifdef CONFIG_PREEMPT_RT_BASE
  22864. + open_softirq(HRTIMER_SOFTIRQ, run_hrtimer_softirq);
  22865. +#endif
  22866. }
  22867. /**
  22868. diff -Nur linux-4.4.13.orig/kernel/time/itimer.c linux-4.4.13/kernel/time/itimer.c
  22869. --- linux-4.4.13.orig/kernel/time/itimer.c 2016-06-08 03:14:51.000000000 +0200
  22870. +++ linux-4.4.13/kernel/time/itimer.c 2016-06-22 21:55:08.062523867 +0200
  22871. @@ -213,6 +213,7 @@
  22872. /* We are sharing ->siglock with it_real_fn() */
  22873. if (hrtimer_try_to_cancel(timer) < 0) {
  22874. spin_unlock_irq(&tsk->sighand->siglock);
  22875. + hrtimer_wait_for_timer(&tsk->signal->real_timer);
  22876. goto again;
  22877. }
  22878. expires = timeval_to_ktime(value->it_value);
  22879. diff -Nur linux-4.4.13.orig/kernel/time/jiffies.c linux-4.4.13/kernel/time/jiffies.c
  22880. --- linux-4.4.13.orig/kernel/time/jiffies.c 2016-06-08 03:14:51.000000000 +0200
  22881. +++ linux-4.4.13/kernel/time/jiffies.c 2016-06-22 21:55:08.062523867 +0200
  22882. @@ -74,7 +74,8 @@
  22883. .max_cycles = 10,
  22884. };
  22885. -__cacheline_aligned_in_smp DEFINE_SEQLOCK(jiffies_lock);
  22886. +__cacheline_aligned_in_smp DEFINE_RAW_SPINLOCK(jiffies_lock);
  22887. +__cacheline_aligned_in_smp seqcount_t jiffies_seq;
  22888. #if (BITS_PER_LONG < 64)
  22889. u64 get_jiffies_64(void)
  22890. @@ -83,9 +84,9 @@
  22891. u64 ret;
  22892. do {
  22893. - seq = read_seqbegin(&jiffies_lock);
  22894. + seq = read_seqcount_begin(&jiffies_seq);
  22895. ret = jiffies_64;
  22896. - } while (read_seqretry(&jiffies_lock, seq));
  22897. + } while (read_seqcount_retry(&jiffies_seq, seq));
  22898. return ret;
  22899. }
  22900. EXPORT_SYMBOL(get_jiffies_64);
  22901. diff -Nur linux-4.4.13.orig/kernel/time/ntp.c linux-4.4.13/kernel/time/ntp.c
  22902. --- linux-4.4.13.orig/kernel/time/ntp.c 2016-06-08 03:14:51.000000000 +0200
  22903. +++ linux-4.4.13/kernel/time/ntp.c 2016-06-22 21:55:08.062523867 +0200
  22904. @@ -10,6 +10,7 @@
  22905. #include <linux/workqueue.h>
  22906. #include <linux/hrtimer.h>
  22907. #include <linux/jiffies.h>
  22908. +#include <linux/kthread.h>
  22909. #include <linux/math64.h>
  22910. #include <linux/timex.h>
  22911. #include <linux/time.h>
  22912. @@ -562,10 +563,52 @@
  22913. &sync_cmos_work, timespec64_to_jiffies(&next));
  22914. }
  22915. +#ifdef CONFIG_PREEMPT_RT_FULL
  22916. +/*
  22917. + * RT can not call schedule_delayed_work from real interrupt context.
  22918. + * Need to make a thread to do the real work.
  22919. + */
  22920. +static struct task_struct *cmos_delay_thread;
  22921. +static bool do_cmos_delay;
  22922. +
  22923. +static int run_cmos_delay(void *ignore)
  22924. +{
  22925. + while (!kthread_should_stop()) {
  22926. + set_current_state(TASK_INTERRUPTIBLE);
  22927. + if (do_cmos_delay) {
  22928. + do_cmos_delay = false;
  22929. + queue_delayed_work(system_power_efficient_wq,
  22930. + &sync_cmos_work, 0);
  22931. + }
  22932. + schedule();
  22933. + }
  22934. + __set_current_state(TASK_RUNNING);
  22935. + return 0;
  22936. +}
  22937. +
  22938. +void ntp_notify_cmos_timer(void)
  22939. +{
  22940. + do_cmos_delay = true;
  22941. + /* Make visible before waking up process */
  22942. + smp_wmb();
  22943. + wake_up_process(cmos_delay_thread);
  22944. +}
  22945. +
  22946. +static __init int create_cmos_delay_thread(void)
  22947. +{
  22948. + cmos_delay_thread = kthread_run(run_cmos_delay, NULL, "kcmosdelayd");
  22949. + BUG_ON(!cmos_delay_thread);
  22950. + return 0;
  22951. +}
  22952. +early_initcall(create_cmos_delay_thread);
  22953. +
  22954. +#else
  22955. +
  22956. void ntp_notify_cmos_timer(void)
  22957. {
  22958. queue_delayed_work(system_power_efficient_wq, &sync_cmos_work, 0);
  22959. }
  22960. +#endif /* CONFIG_PREEMPT_RT_FULL */
  22961. #else
  22962. void ntp_notify_cmos_timer(void) { }
  22963. diff -Nur linux-4.4.13.orig/kernel/time/posix-cpu-timers.c linux-4.4.13/kernel/time/posix-cpu-timers.c
  22964. --- linux-4.4.13.orig/kernel/time/posix-cpu-timers.c 2016-06-08 03:14:51.000000000 +0200
  22965. +++ linux-4.4.13/kernel/time/posix-cpu-timers.c 2016-06-22 21:55:08.066523867 +0200
  22966. @@ -3,6 +3,7 @@
  22967. */
  22968. #include <linux/sched.h>
  22969. +#include <linux/sched/rt.h>
  22970. #include <linux/posix-timers.h>
  22971. #include <linux/errno.h>
  22972. #include <linux/math64.h>
  22973. @@ -650,7 +651,7 @@
  22974. /*
  22975. * Disarm any old timer after extracting its expiry time.
  22976. */
  22977. - WARN_ON_ONCE(!irqs_disabled());
  22978. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  22979. ret = 0;
  22980. old_incr = timer->it.cpu.incr;
  22981. @@ -1091,7 +1092,7 @@
  22982. /*
  22983. * Now re-arm for the new expiry time.
  22984. */
  22985. - WARN_ON_ONCE(!irqs_disabled());
  22986. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  22987. arm_timer(timer);
  22988. unlock_task_sighand(p, &flags);
  22989. @@ -1182,13 +1183,13 @@
  22990. * already updated our counts. We need to check if any timers fire now.
  22991. * Interrupts are disabled.
  22992. */
  22993. -void run_posix_cpu_timers(struct task_struct *tsk)
  22994. +static void __run_posix_cpu_timers(struct task_struct *tsk)
  22995. {
  22996. LIST_HEAD(firing);
  22997. struct k_itimer *timer, *next;
  22998. unsigned long flags;
  22999. - WARN_ON_ONCE(!irqs_disabled());
  23000. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  23001. /*
  23002. * The fast path checks that there are no expired thread or thread
  23003. @@ -1242,6 +1243,190 @@
  23004. }
  23005. }
  23006. +#ifdef CONFIG_PREEMPT_RT_BASE
  23007. +#include <linux/kthread.h>
  23008. +#include <linux/cpu.h>
  23009. +DEFINE_PER_CPU(struct task_struct *, posix_timer_task);
  23010. +DEFINE_PER_CPU(struct task_struct *, posix_timer_tasklist);
  23011. +
  23012. +static int posix_cpu_timers_thread(void *data)
  23013. +{
  23014. + int cpu = (long)data;
  23015. +
  23016. + BUG_ON(per_cpu(posix_timer_task,cpu) != current);
  23017. +
  23018. + while (!kthread_should_stop()) {
  23019. + struct task_struct *tsk = NULL;
  23020. + struct task_struct *next = NULL;
  23021. +
  23022. + if (cpu_is_offline(cpu))
  23023. + goto wait_to_die;
  23024. +
  23025. + /* grab task list */
  23026. + raw_local_irq_disable();
  23027. + tsk = per_cpu(posix_timer_tasklist, cpu);
  23028. + per_cpu(posix_timer_tasklist, cpu) = NULL;
  23029. + raw_local_irq_enable();
  23030. +
  23031. + /* its possible the list is empty, just return */
  23032. + if (!tsk) {
  23033. + set_current_state(TASK_INTERRUPTIBLE);
  23034. + schedule();
  23035. + __set_current_state(TASK_RUNNING);
  23036. + continue;
  23037. + }
  23038. +
  23039. + /* Process task list */
  23040. + while (1) {
  23041. + /* save next */
  23042. + next = tsk->posix_timer_list;
  23043. +
  23044. + /* run the task timers, clear its ptr and
  23045. + * unreference it
  23046. + */
  23047. + __run_posix_cpu_timers(tsk);
  23048. + tsk->posix_timer_list = NULL;
  23049. + put_task_struct(tsk);
  23050. +
  23051. + /* check if this is the last on the list */
  23052. + if (next == tsk)
  23053. + break;
  23054. + tsk = next;
  23055. + }
  23056. + }
  23057. + return 0;
  23058. +
  23059. +wait_to_die:
  23060. + /* Wait for kthread_stop */
  23061. + set_current_state(TASK_INTERRUPTIBLE);
  23062. + while (!kthread_should_stop()) {
  23063. + schedule();
  23064. + set_current_state(TASK_INTERRUPTIBLE);
  23065. + }
  23066. + __set_current_state(TASK_RUNNING);
  23067. + return 0;
  23068. +}
  23069. +
  23070. +static inline int __fastpath_timer_check(struct task_struct *tsk)
  23071. +{
  23072. + /* tsk == current, ensure it is safe to use ->signal/sighand */
  23073. + if (unlikely(tsk->exit_state))
  23074. + return 0;
  23075. +
  23076. + if (!task_cputime_zero(&tsk->cputime_expires))
  23077. + return 1;
  23078. +
  23079. + if (!task_cputime_zero(&tsk->signal->cputime_expires))
  23080. + return 1;
  23081. +
  23082. + return 0;
  23083. +}
  23084. +
  23085. +void run_posix_cpu_timers(struct task_struct *tsk)
  23086. +{
  23087. + unsigned long cpu = smp_processor_id();
  23088. + struct task_struct *tasklist;
  23089. +
  23090. + BUG_ON(!irqs_disabled());
  23091. + if(!per_cpu(posix_timer_task, cpu))
  23092. + return;
  23093. + /* get per-cpu references */
  23094. + tasklist = per_cpu(posix_timer_tasklist, cpu);
  23095. +
  23096. + /* check to see if we're already queued */
  23097. + if (!tsk->posix_timer_list && __fastpath_timer_check(tsk)) {
  23098. + get_task_struct(tsk);
  23099. + if (tasklist) {
  23100. + tsk->posix_timer_list = tasklist;
  23101. + } else {
  23102. + /*
  23103. + * The list is terminated by a self-pointing
  23104. + * task_struct
  23105. + */
  23106. + tsk->posix_timer_list = tsk;
  23107. + }
  23108. + per_cpu(posix_timer_tasklist, cpu) = tsk;
  23109. +
  23110. + wake_up_process(per_cpu(posix_timer_task, cpu));
  23111. + }
  23112. +}
  23113. +
  23114. +/*
  23115. + * posix_cpu_thread_call - callback that gets triggered when a CPU is added.
  23116. + * Here we can start up the necessary migration thread for the new CPU.
  23117. + */
  23118. +static int posix_cpu_thread_call(struct notifier_block *nfb,
  23119. + unsigned long action, void *hcpu)
  23120. +{
  23121. + int cpu = (long)hcpu;
  23122. + struct task_struct *p;
  23123. + struct sched_param param;
  23124. +
  23125. + switch (action) {
  23126. + case CPU_UP_PREPARE:
  23127. + p = kthread_create(posix_cpu_timers_thread, hcpu,
  23128. + "posixcputmr/%d",cpu);
  23129. + if (IS_ERR(p))
  23130. + return NOTIFY_BAD;
  23131. + p->flags |= PF_NOFREEZE;
  23132. + kthread_bind(p, cpu);
  23133. + /* Must be high prio to avoid getting starved */
  23134. + param.sched_priority = MAX_RT_PRIO-1;
  23135. + sched_setscheduler(p, SCHED_FIFO, &param);
  23136. + per_cpu(posix_timer_task,cpu) = p;
  23137. + break;
  23138. + case CPU_ONLINE:
  23139. + /* Strictly unneccessary, as first user will wake it. */
  23140. + wake_up_process(per_cpu(posix_timer_task,cpu));
  23141. + break;
  23142. +#ifdef CONFIG_HOTPLUG_CPU
  23143. + case CPU_UP_CANCELED:
  23144. + /* Unbind it from offline cpu so it can run. Fall thru. */
  23145. + kthread_bind(per_cpu(posix_timer_task, cpu),
  23146. + cpumask_any(cpu_online_mask));
  23147. + kthread_stop(per_cpu(posix_timer_task,cpu));
  23148. + per_cpu(posix_timer_task,cpu) = NULL;
  23149. + break;
  23150. + case CPU_DEAD:
  23151. + kthread_stop(per_cpu(posix_timer_task,cpu));
  23152. + per_cpu(posix_timer_task,cpu) = NULL;
  23153. + break;
  23154. +#endif
  23155. + }
  23156. + return NOTIFY_OK;
  23157. +}
  23158. +
  23159. +/* Register at highest priority so that task migration (migrate_all_tasks)
  23160. + * happens before everything else.
  23161. + */
  23162. +static struct notifier_block posix_cpu_thread_notifier = {
  23163. + .notifier_call = posix_cpu_thread_call,
  23164. + .priority = 10
  23165. +};
  23166. +
  23167. +static int __init posix_cpu_thread_init(void)
  23168. +{
  23169. + void *hcpu = (void *)(long)smp_processor_id();
  23170. + /* Start one for boot CPU. */
  23171. + unsigned long cpu;
  23172. +
  23173. + /* init the per-cpu posix_timer_tasklets */
  23174. + for_each_possible_cpu(cpu)
  23175. + per_cpu(posix_timer_tasklist, cpu) = NULL;
  23176. +
  23177. + posix_cpu_thread_call(&posix_cpu_thread_notifier, CPU_UP_PREPARE, hcpu);
  23178. + posix_cpu_thread_call(&posix_cpu_thread_notifier, CPU_ONLINE, hcpu);
  23179. + register_cpu_notifier(&posix_cpu_thread_notifier);
  23180. + return 0;
  23181. +}
  23182. +early_initcall(posix_cpu_thread_init);
  23183. +#else /* CONFIG_PREEMPT_RT_BASE */
  23184. +void run_posix_cpu_timers(struct task_struct *tsk)
  23185. +{
  23186. + __run_posix_cpu_timers(tsk);
  23187. +}
  23188. +#endif /* CONFIG_PREEMPT_RT_BASE */
  23189. +
  23190. /*
  23191. * Set one of the process-wide special case CPU timers or RLIMIT_CPU.
  23192. * The tsk->sighand->siglock must be held by the caller.
  23193. diff -Nur linux-4.4.13.orig/kernel/time/posix-timers.c linux-4.4.13/kernel/time/posix-timers.c
  23194. --- linux-4.4.13.orig/kernel/time/posix-timers.c 2016-06-08 03:14:51.000000000 +0200
  23195. +++ linux-4.4.13/kernel/time/posix-timers.c 2016-06-22 21:55:08.066523867 +0200
  23196. @@ -506,6 +506,7 @@
  23197. static struct pid *good_sigevent(sigevent_t * event)
  23198. {
  23199. struct task_struct *rtn = current->group_leader;
  23200. + int sig = event->sigev_signo;
  23201. if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
  23202. (!(rtn = find_task_by_vpid(event->sigev_notify_thread_id)) ||
  23203. @@ -514,7 +515,8 @@
  23204. return NULL;
  23205. if (((event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) &&
  23206. - ((event->sigev_signo <= 0) || (event->sigev_signo > SIGRTMAX)))
  23207. + (sig <= 0 || sig > SIGRTMAX || sig_kernel_only(sig) ||
  23208. + sig_kernel_coredump(sig)))
  23209. return NULL;
  23210. return task_pid(rtn);
  23211. @@ -826,6 +828,20 @@
  23212. return overrun;
  23213. }
  23214. +/*
  23215. + * Protected by RCU!
  23216. + */
  23217. +static void timer_wait_for_callback(struct k_clock *kc, struct k_itimer *timr)
  23218. +{
  23219. +#ifdef CONFIG_PREEMPT_RT_FULL
  23220. + if (kc->timer_set == common_timer_set)
  23221. + hrtimer_wait_for_timer(&timr->it.real.timer);
  23222. + else
  23223. + /* FIXME: Whacky hack for posix-cpu-timers */
  23224. + schedule_timeout(1);
  23225. +#endif
  23226. +}
  23227. +
  23228. /* Set a POSIX.1b interval timer. */
  23229. /* timr->it_lock is taken. */
  23230. static int
  23231. @@ -903,6 +919,7 @@
  23232. if (!timr)
  23233. return -EINVAL;
  23234. + rcu_read_lock();
  23235. kc = clockid_to_kclock(timr->it_clock);
  23236. if (WARN_ON_ONCE(!kc || !kc->timer_set))
  23237. error = -EINVAL;
  23238. @@ -911,9 +928,12 @@
  23239. unlock_timer(timr, flag);
  23240. if (error == TIMER_RETRY) {
  23241. + timer_wait_for_callback(kc, timr);
  23242. rtn = NULL; // We already got the old time...
  23243. + rcu_read_unlock();
  23244. goto retry;
  23245. }
  23246. + rcu_read_unlock();
  23247. if (old_setting && !error &&
  23248. copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
  23249. @@ -951,10 +971,15 @@
  23250. if (!timer)
  23251. return -EINVAL;
  23252. + rcu_read_lock();
  23253. if (timer_delete_hook(timer) == TIMER_RETRY) {
  23254. unlock_timer(timer, flags);
  23255. + timer_wait_for_callback(clockid_to_kclock(timer->it_clock),
  23256. + timer);
  23257. + rcu_read_unlock();
  23258. goto retry_delete;
  23259. }
  23260. + rcu_read_unlock();
  23261. spin_lock(&current->sighand->siglock);
  23262. list_del(&timer->list);
  23263. @@ -980,8 +1005,18 @@
  23264. retry_delete:
  23265. spin_lock_irqsave(&timer->it_lock, flags);
  23266. + /* On RT we can race with a deletion */
  23267. + if (!timer->it_signal) {
  23268. + unlock_timer(timer, flags);
  23269. + return;
  23270. + }
  23271. +
  23272. if (timer_delete_hook(timer) == TIMER_RETRY) {
  23273. + rcu_read_lock();
  23274. unlock_timer(timer, flags);
  23275. + timer_wait_for_callback(clockid_to_kclock(timer->it_clock),
  23276. + timer);
  23277. + rcu_read_unlock();
  23278. goto retry_delete;
  23279. }
  23280. list_del(&timer->list);
  23281. diff -Nur linux-4.4.13.orig/kernel/time/tick-broadcast-hrtimer.c linux-4.4.13/kernel/time/tick-broadcast-hrtimer.c
  23282. --- linux-4.4.13.orig/kernel/time/tick-broadcast-hrtimer.c 2016-06-08 03:14:51.000000000 +0200
  23283. +++ linux-4.4.13/kernel/time/tick-broadcast-hrtimer.c 2016-06-22 21:55:08.066523867 +0200
  23284. @@ -106,5 +106,6 @@
  23285. {
  23286. hrtimer_init(&bctimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  23287. bctimer.function = bc_handler;
  23288. + bctimer.irqsafe = true;
  23289. clockevents_register_device(&ce_broadcast_hrtimer);
  23290. }
  23291. diff -Nur linux-4.4.13.orig/kernel/time/tick-common.c linux-4.4.13/kernel/time/tick-common.c
  23292. --- linux-4.4.13.orig/kernel/time/tick-common.c 2016-06-08 03:14:51.000000000 +0200
  23293. +++ linux-4.4.13/kernel/time/tick-common.c 2016-06-22 21:55:08.066523867 +0200
  23294. @@ -79,13 +79,15 @@
  23295. static void tick_periodic(int cpu)
  23296. {
  23297. if (tick_do_timer_cpu == cpu) {
  23298. - write_seqlock(&jiffies_lock);
  23299. + raw_spin_lock(&jiffies_lock);
  23300. + write_seqcount_begin(&jiffies_seq);
  23301. /* Keep track of the next tick event */
  23302. tick_next_period = ktime_add(tick_next_period, tick_period);
  23303. do_timer(1);
  23304. - write_sequnlock(&jiffies_lock);
  23305. + write_seqcount_end(&jiffies_seq);
  23306. + raw_spin_unlock(&jiffies_lock);
  23307. update_wall_time();
  23308. }
  23309. @@ -157,9 +159,9 @@
  23310. ktime_t next;
  23311. do {
  23312. - seq = read_seqbegin(&jiffies_lock);
  23313. + seq = read_seqcount_begin(&jiffies_seq);
  23314. next = tick_next_period;
  23315. - } while (read_seqretry(&jiffies_lock, seq));
  23316. + } while (read_seqcount_retry(&jiffies_seq, seq));
  23317. clockevents_switch_state(dev, CLOCK_EVT_STATE_ONESHOT);
  23318. diff -Nur linux-4.4.13.orig/kernel/time/tick-sched.c linux-4.4.13/kernel/time/tick-sched.c
  23319. --- linux-4.4.13.orig/kernel/time/tick-sched.c 2016-06-08 03:14:51.000000000 +0200
  23320. +++ linux-4.4.13/kernel/time/tick-sched.c 2016-06-22 21:55:08.066523867 +0200
  23321. @@ -62,7 +62,8 @@
  23322. return;
  23323. /* Reevalute with jiffies_lock held */
  23324. - write_seqlock(&jiffies_lock);
  23325. + raw_spin_lock(&jiffies_lock);
  23326. + write_seqcount_begin(&jiffies_seq);
  23327. delta = ktime_sub(now, last_jiffies_update);
  23328. if (delta.tv64 >= tick_period.tv64) {
  23329. @@ -85,10 +86,12 @@
  23330. /* Keep the tick_next_period variable up to date */
  23331. tick_next_period = ktime_add(last_jiffies_update, tick_period);
  23332. } else {
  23333. - write_sequnlock(&jiffies_lock);
  23334. + write_seqcount_end(&jiffies_seq);
  23335. + raw_spin_unlock(&jiffies_lock);
  23336. return;
  23337. }
  23338. - write_sequnlock(&jiffies_lock);
  23339. + write_seqcount_end(&jiffies_seq);
  23340. + raw_spin_unlock(&jiffies_lock);
  23341. update_wall_time();
  23342. }
  23343. @@ -99,12 +102,14 @@
  23344. {
  23345. ktime_t period;
  23346. - write_seqlock(&jiffies_lock);
  23347. + raw_spin_lock(&jiffies_lock);
  23348. + write_seqcount_begin(&jiffies_seq);
  23349. /* Did we start the jiffies update yet ? */
  23350. if (last_jiffies_update.tv64 == 0)
  23351. last_jiffies_update = tick_next_period;
  23352. period = last_jiffies_update;
  23353. - write_sequnlock(&jiffies_lock);
  23354. + write_seqcount_end(&jiffies_seq);
  23355. + raw_spin_unlock(&jiffies_lock);
  23356. return period;
  23357. }
  23358. @@ -176,6 +181,11 @@
  23359. return false;
  23360. }
  23361. + if (!arch_irq_work_has_interrupt()) {
  23362. + trace_tick_stop(0, "missing irq work interrupt\n");
  23363. + return false;
  23364. + }
  23365. +
  23366. /* sched_clock_tick() needs us? */
  23367. #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
  23368. /*
  23369. @@ -204,6 +214,7 @@
  23370. static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) = {
  23371. .func = nohz_full_kick_work_func,
  23372. + .flags = IRQ_WORK_HARD_IRQ,
  23373. };
  23374. /*
  23375. @@ -578,10 +589,10 @@
  23376. /* Read jiffies and the time when jiffies were updated last */
  23377. do {
  23378. - seq = read_seqbegin(&jiffies_lock);
  23379. + seq = read_seqcount_begin(&jiffies_seq);
  23380. basemono = last_jiffies_update.tv64;
  23381. basejiff = jiffies;
  23382. - } while (read_seqretry(&jiffies_lock, seq));
  23383. + } while (read_seqcount_retry(&jiffies_seq, seq));
  23384. ts->last_jiffies = basejiff;
  23385. if (rcu_needs_cpu(basemono, &next_rcu) ||
  23386. @@ -753,14 +764,7 @@
  23387. return false;
  23388. if (unlikely(local_softirq_pending() && cpu_online(cpu))) {
  23389. - static int ratelimit;
  23390. -
  23391. - if (ratelimit < 10 &&
  23392. - (local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK)) {
  23393. - pr_warn("NOHZ: local_softirq_pending %02x\n",
  23394. - (unsigned int) local_softirq_pending());
  23395. - ratelimit++;
  23396. - }
  23397. + softirq_check_pending_idle();
  23398. return false;
  23399. }
  23400. @@ -1100,6 +1104,7 @@
  23401. * Emulate tick processing via per-CPU hrtimers:
  23402. */
  23403. hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  23404. + ts->sched_timer.irqsafe = 1;
  23405. ts->sched_timer.function = tick_sched_timer;
  23406. /* Get the next period (per cpu) */
  23407. diff -Nur linux-4.4.13.orig/kernel/time/timekeeping.c linux-4.4.13/kernel/time/timekeeping.c
  23408. --- linux-4.4.13.orig/kernel/time/timekeeping.c 2016-06-08 03:14:51.000000000 +0200
  23409. +++ linux-4.4.13/kernel/time/timekeeping.c 2016-06-22 21:55:08.066523867 +0200
  23410. @@ -2047,8 +2047,10 @@
  23411. */
  23412. void xtime_update(unsigned long ticks)
  23413. {
  23414. - write_seqlock(&jiffies_lock);
  23415. + raw_spin_lock(&jiffies_lock);
  23416. + write_seqcount_begin(&jiffies_seq);
  23417. do_timer(ticks);
  23418. - write_sequnlock(&jiffies_lock);
  23419. + write_seqcount_end(&jiffies_seq);
  23420. + raw_spin_unlock(&jiffies_lock);
  23421. update_wall_time();
  23422. }
  23423. diff -Nur linux-4.4.13.orig/kernel/time/timekeeping.h linux-4.4.13/kernel/time/timekeeping.h
  23424. --- linux-4.4.13.orig/kernel/time/timekeeping.h 2016-06-08 03:14:51.000000000 +0200
  23425. +++ linux-4.4.13/kernel/time/timekeeping.h 2016-06-22 21:55:08.066523867 +0200
  23426. @@ -19,7 +19,8 @@
  23427. extern void do_timer(unsigned long ticks);
  23428. extern void update_wall_time(void);
  23429. -extern seqlock_t jiffies_lock;
  23430. +extern raw_spinlock_t jiffies_lock;
  23431. +extern seqcount_t jiffies_seq;
  23432. #define CS_NAME_LEN 32
  23433. diff -Nur linux-4.4.13.orig/kernel/time/timer.c linux-4.4.13/kernel/time/timer.c
  23434. --- linux-4.4.13.orig/kernel/time/timer.c 2016-06-08 03:14:51.000000000 +0200
  23435. +++ linux-4.4.13/kernel/time/timer.c 2016-06-22 21:55:08.066523867 +0200
  23436. @@ -80,6 +80,9 @@
  23437. struct tvec_base {
  23438. spinlock_t lock;
  23439. struct timer_list *running_timer;
  23440. +#ifdef CONFIG_PREEMPT_RT_FULL
  23441. + wait_queue_head_t wait_for_running_timer;
  23442. +#endif
  23443. unsigned long timer_jiffies;
  23444. unsigned long next_timer;
  23445. unsigned long active_timers;
  23446. @@ -777,6 +780,39 @@
  23447. cpu_relax();
  23448. }
  23449. }
  23450. +#ifdef CONFIG_PREEMPT_RT_FULL
  23451. +static inline struct tvec_base *switch_timer_base(struct timer_list *timer,
  23452. + struct tvec_base *old,
  23453. + struct tvec_base *new)
  23454. +{
  23455. + /*
  23456. + * We cannot do the below because we might be preempted and
  23457. + * then the preempter would see NULL and loop forever.
  23458. + */
  23459. + if (spin_trylock(&new->lock)) {
  23460. + WRITE_ONCE(timer->flags,
  23461. + (timer->flags & ~TIMER_BASEMASK) | new->cpu);
  23462. + spin_unlock(&old->lock);
  23463. + return new;
  23464. + }
  23465. + return old;
  23466. +}
  23467. +
  23468. +#else
  23469. +static inline struct tvec_base *switch_timer_base(struct timer_list *timer,
  23470. + struct tvec_base *old,
  23471. + struct tvec_base *new)
  23472. +{
  23473. + /* See the comment in lock_timer_base() */
  23474. + timer->flags |= TIMER_MIGRATING;
  23475. +
  23476. + spin_unlock(&old->lock);
  23477. + spin_lock(&new->lock);
  23478. + WRITE_ONCE(timer->flags,
  23479. + (timer->flags & ~TIMER_BASEMASK) | new->cpu);
  23480. + return new;
  23481. +}
  23482. +#endif
  23483. static inline int
  23484. __mod_timer(struct timer_list *timer, unsigned long expires,
  23485. @@ -807,16 +843,8 @@
  23486. * handler yet has not finished. This also guarantees that
  23487. * the timer is serialized wrt itself.
  23488. */
  23489. - if (likely(base->running_timer != timer)) {
  23490. - /* See the comment in lock_timer_base() */
  23491. - timer->flags |= TIMER_MIGRATING;
  23492. -
  23493. - spin_unlock(&base->lock);
  23494. - base = new_base;
  23495. - spin_lock(&base->lock);
  23496. - WRITE_ONCE(timer->flags,
  23497. - (timer->flags & ~TIMER_BASEMASK) | base->cpu);
  23498. - }
  23499. + if (likely(base->running_timer != timer))
  23500. + base = switch_timer_base(timer, base, new_base);
  23501. }
  23502. timer->expires = expires;
  23503. @@ -1006,6 +1034,33 @@
  23504. }
  23505. EXPORT_SYMBOL_GPL(add_timer_on);
  23506. +#ifdef CONFIG_PREEMPT_RT_FULL
  23507. +/*
  23508. + * Wait for a running timer
  23509. + */
  23510. +static void wait_for_running_timer(struct timer_list *timer)
  23511. +{
  23512. + struct tvec_base *base;
  23513. + u32 tf = timer->flags;
  23514. +
  23515. + if (tf & TIMER_MIGRATING)
  23516. + return;
  23517. +
  23518. + base = per_cpu_ptr(&tvec_bases, tf & TIMER_CPUMASK);
  23519. + wait_event(base->wait_for_running_timer,
  23520. + base->running_timer != timer);
  23521. +}
  23522. +
  23523. +# define wakeup_timer_waiters(b) wake_up(&(b)->wait_for_running_timer)
  23524. +#else
  23525. +static inline void wait_for_running_timer(struct timer_list *timer)
  23526. +{
  23527. + cpu_relax();
  23528. +}
  23529. +
  23530. +# define wakeup_timer_waiters(b) do { } while (0)
  23531. +#endif
  23532. +
  23533. /**
  23534. * del_timer - deactive a timer.
  23535. * @timer: the timer to be deactivated
  23536. @@ -1063,7 +1118,7 @@
  23537. }
  23538. EXPORT_SYMBOL(try_to_del_timer_sync);
  23539. -#ifdef CONFIG_SMP
  23540. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  23541. /**
  23542. * del_timer_sync - deactivate a timer and wait for the handler to finish.
  23543. * @timer: the timer to be deactivated
  23544. @@ -1123,7 +1178,7 @@
  23545. int ret = try_to_del_timer_sync(timer);
  23546. if (ret >= 0)
  23547. return ret;
  23548. - cpu_relax();
  23549. + wait_for_running_timer(timer);
  23550. }
  23551. }
  23552. EXPORT_SYMBOL(del_timer_sync);
  23553. @@ -1248,15 +1303,17 @@
  23554. if (irqsafe) {
  23555. spin_unlock(&base->lock);
  23556. call_timer_fn(timer, fn, data);
  23557. + base->running_timer = NULL;
  23558. spin_lock(&base->lock);
  23559. } else {
  23560. spin_unlock_irq(&base->lock);
  23561. call_timer_fn(timer, fn, data);
  23562. + base->running_timer = NULL;
  23563. spin_lock_irq(&base->lock);
  23564. }
  23565. }
  23566. }
  23567. - base->running_timer = NULL;
  23568. + wakeup_timer_waiters(base);
  23569. spin_unlock_irq(&base->lock);
  23570. }
  23571. @@ -1390,6 +1447,14 @@
  23572. if (cpu_is_offline(smp_processor_id()))
  23573. return expires;
  23574. +#ifdef CONFIG_PREEMPT_RT_FULL
  23575. + /*
  23576. + * On PREEMPT_RT we cannot sleep here. As a result we can't take
  23577. + * the base lock to check when the next timer is pending and so
  23578. + * we assume the next jiffy.
  23579. + */
  23580. + return basem + TICK_NSEC;
  23581. +#endif
  23582. spin_lock(&base->lock);
  23583. if (base->active_timers) {
  23584. if (time_before_eq(base->next_timer, base->timer_jiffies))
  23585. @@ -1416,13 +1481,13 @@
  23586. /* Note: this timer irq context must be accounted for as well. */
  23587. account_process_tick(p, user_tick);
  23588. + scheduler_tick();
  23589. run_local_timers();
  23590. rcu_check_callbacks(user_tick);
  23591. -#ifdef CONFIG_IRQ_WORK
  23592. +#if defined(CONFIG_IRQ_WORK)
  23593. if (in_irq())
  23594. irq_work_tick();
  23595. #endif
  23596. - scheduler_tick();
  23597. run_posix_cpu_timers(p);
  23598. }
  23599. @@ -1433,6 +1498,8 @@
  23600. {
  23601. struct tvec_base *base = this_cpu_ptr(&tvec_bases);
  23602. + irq_work_tick_soft();
  23603. +
  23604. if (time_after_eq(jiffies, base->timer_jiffies))
  23605. __run_timers(base);
  23606. }
  23607. @@ -1589,7 +1656,7 @@
  23608. BUG_ON(cpu_online(cpu));
  23609. old_base = per_cpu_ptr(&tvec_bases, cpu);
  23610. - new_base = get_cpu_ptr(&tvec_bases);
  23611. + new_base = get_local_ptr(&tvec_bases);
  23612. /*
  23613. * The caller is globally serialized and nobody else
  23614. * takes two locks at once, deadlock is not possible.
  23615. @@ -1613,7 +1680,7 @@
  23616. spin_unlock(&old_base->lock);
  23617. spin_unlock_irq(&new_base->lock);
  23618. - put_cpu_ptr(&tvec_bases);
  23619. + put_local_ptr(&tvec_bases);
  23620. }
  23621. static int timer_cpu_notify(struct notifier_block *self,
  23622. @@ -1645,6 +1712,9 @@
  23623. base->cpu = cpu;
  23624. spin_lock_init(&base->lock);
  23625. +#ifdef CONFIG_PREEMPT_RT_FULL
  23626. + init_waitqueue_head(&base->wait_for_running_timer);
  23627. +#endif
  23628. base->timer_jiffies = jiffies;
  23629. base->next_timer = base->timer_jiffies;
  23630. diff -Nur linux-4.4.13.orig/kernel/trace/Kconfig linux-4.4.13/kernel/trace/Kconfig
  23631. --- linux-4.4.13.orig/kernel/trace/Kconfig 2016-06-08 03:14:51.000000000 +0200
  23632. +++ linux-4.4.13/kernel/trace/Kconfig 2016-06-22 21:55:08.066523867 +0200
  23633. @@ -187,6 +187,24 @@
  23634. enabled. This option and the preempt-off timing option can be
  23635. used together or separately.)
  23636. +config INTERRUPT_OFF_HIST
  23637. + bool "Interrupts-off Latency Histogram"
  23638. + depends on IRQSOFF_TRACER
  23639. + help
  23640. + This option generates continuously updated histograms (one per cpu)
  23641. + of the duration of time periods with interrupts disabled. The
  23642. + histograms are disabled by default. To enable them, write a non-zero
  23643. + number to
  23644. +
  23645. + /sys/kernel/debug/tracing/latency_hist/enable/preemptirqsoff
  23646. +
  23647. + If PREEMPT_OFF_HIST is also selected, additional histograms (one
  23648. + per cpu) are generated that accumulate the duration of time periods
  23649. + when both interrupts and preemption are disabled. The histogram data
  23650. + will be located in the debug file system at
  23651. +
  23652. + /sys/kernel/debug/tracing/latency_hist/irqsoff
  23653. +
  23654. config PREEMPT_TRACER
  23655. bool "Preemption-off Latency Tracer"
  23656. default n
  23657. @@ -211,6 +229,24 @@
  23658. enabled. This option and the irqs-off timing option can be
  23659. used together or separately.)
  23660. +config PREEMPT_OFF_HIST
  23661. + bool "Preemption-off Latency Histogram"
  23662. + depends on PREEMPT_TRACER
  23663. + help
  23664. + This option generates continuously updated histograms (one per cpu)
  23665. + of the duration of time periods with preemption disabled. The
  23666. + histograms are disabled by default. To enable them, write a non-zero
  23667. + number to
  23668. +
  23669. + /sys/kernel/debug/tracing/latency_hist/enable/preemptirqsoff
  23670. +
  23671. + If INTERRUPT_OFF_HIST is also selected, additional histograms (one
  23672. + per cpu) are generated that accumulate the duration of time periods
  23673. + when both interrupts and preemption are disabled. The histogram data
  23674. + will be located in the debug file system at
  23675. +
  23676. + /sys/kernel/debug/tracing/latency_hist/preemptoff
  23677. +
  23678. config SCHED_TRACER
  23679. bool "Scheduling Latency Tracer"
  23680. select GENERIC_TRACER
  23681. @@ -221,6 +257,74 @@
  23682. This tracer tracks the latency of the highest priority task
  23683. to be scheduled in, starting from the point it has woken up.
  23684. +config WAKEUP_LATENCY_HIST
  23685. + bool "Scheduling Latency Histogram"
  23686. + depends on SCHED_TRACER
  23687. + help
  23688. + This option generates continuously updated histograms (one per cpu)
  23689. + of the scheduling latency of the highest priority task.
  23690. + The histograms are disabled by default. To enable them, write a
  23691. + non-zero number to
  23692. +
  23693. + /sys/kernel/debug/tracing/latency_hist/enable/wakeup
  23694. +
  23695. + Two different algorithms are used, one to determine the latency of
  23696. + processes that exclusively use the highest priority of the system and
  23697. + another one to determine the latency of processes that share the
  23698. + highest system priority with other processes. The former is used to
  23699. + improve hardware and system software, the latter to optimize the
  23700. + priority design of a given system. The histogram data will be
  23701. + located in the debug file system at
  23702. +
  23703. + /sys/kernel/debug/tracing/latency_hist/wakeup
  23704. +
  23705. + and
  23706. +
  23707. + /sys/kernel/debug/tracing/latency_hist/wakeup/sharedprio
  23708. +
  23709. + If both Scheduling Latency Histogram and Missed Timer Offsets
  23710. + Histogram are selected, additional histogram data will be collected
  23711. + that contain, in addition to the wakeup latency, the timer latency, in
  23712. + case the wakeup was triggered by an expired timer. These histograms
  23713. + are available in the
  23714. +
  23715. + /sys/kernel/debug/tracing/latency_hist/timerandwakeup
  23716. +
  23717. + directory. They reflect the apparent interrupt and scheduling latency
  23718. + and are best suitable to determine the worst-case latency of a given
  23719. + system. To enable these histograms, write a non-zero number to
  23720. +
  23721. + /sys/kernel/debug/tracing/latency_hist/enable/timerandwakeup
  23722. +
  23723. +config MISSED_TIMER_OFFSETS_HIST
  23724. + depends on HIGH_RES_TIMERS
  23725. + select GENERIC_TRACER
  23726. + bool "Missed Timer Offsets Histogram"
  23727. + help
  23728. + Generate a histogram of missed timer offsets in microseconds. The
  23729. + histograms are disabled by default. To enable them, write a non-zero
  23730. + number to
  23731. +
  23732. + /sys/kernel/debug/tracing/latency_hist/enable/missed_timer_offsets
  23733. +
  23734. + The histogram data will be located in the debug file system at
  23735. +
  23736. + /sys/kernel/debug/tracing/latency_hist/missed_timer_offsets
  23737. +
  23738. + If both Scheduling Latency Histogram and Missed Timer Offsets
  23739. + Histogram are selected, additional histogram data will be collected
  23740. + that contain, in addition to the wakeup latency, the timer latency, in
  23741. + case the wakeup was triggered by an expired timer. These histograms
  23742. + are available in the
  23743. +
  23744. + /sys/kernel/debug/tracing/latency_hist/timerandwakeup
  23745. +
  23746. + directory. They reflect the apparent interrupt and scheduling latency
  23747. + and are best suitable to determine the worst-case latency of a given
  23748. + system. To enable these histograms, write a non-zero number to
  23749. +
  23750. + /sys/kernel/debug/tracing/latency_hist/enable/timerandwakeup
  23751. +
  23752. config ENABLE_DEFAULT_TRACERS
  23753. bool "Trace process context switches and events"
  23754. depends on !GENERIC_TRACER
  23755. diff -Nur linux-4.4.13.orig/kernel/trace/latency_hist.c linux-4.4.13/kernel/trace/latency_hist.c
  23756. --- linux-4.4.13.orig/kernel/trace/latency_hist.c 1970-01-01 01:00:00.000000000 +0100
  23757. +++ linux-4.4.13/kernel/trace/latency_hist.c 2016-06-22 21:55:08.066523867 +0200
  23758. @@ -0,0 +1,1178 @@
  23759. +/*
  23760. + * kernel/trace/latency_hist.c
  23761. + *
  23762. + * Add support for histograms of preemption-off latency and
  23763. + * interrupt-off latency and wakeup latency, it depends on
  23764. + * Real-Time Preemption Support.
  23765. + *
  23766. + * Copyright (C) 2005 MontaVista Software, Inc.
  23767. + * Yi Yang <yyang@ch.mvista.com>
  23768. + *
  23769. + * Converted to work with the new latency tracer.
  23770. + * Copyright (C) 2008 Red Hat, Inc.
  23771. + * Steven Rostedt <srostedt@redhat.com>
  23772. + *
  23773. + */
  23774. +#include <linux/module.h>
  23775. +#include <linux/debugfs.h>
  23776. +#include <linux/seq_file.h>
  23777. +#include <linux/percpu.h>
  23778. +#include <linux/kallsyms.h>
  23779. +#include <linux/uaccess.h>
  23780. +#include <linux/sched.h>
  23781. +#include <linux/sched/rt.h>
  23782. +#include <linux/slab.h>
  23783. +#include <linux/atomic.h>
  23784. +#include <asm/div64.h>
  23785. +
  23786. +#include "trace.h"
  23787. +#include <trace/events/sched.h>
  23788. +
  23789. +#define NSECS_PER_USECS 1000L
  23790. +
  23791. +#define CREATE_TRACE_POINTS
  23792. +#include <trace/events/hist.h>
  23793. +
  23794. +enum {
  23795. + IRQSOFF_LATENCY = 0,
  23796. + PREEMPTOFF_LATENCY,
  23797. + PREEMPTIRQSOFF_LATENCY,
  23798. + WAKEUP_LATENCY,
  23799. + WAKEUP_LATENCY_SHAREDPRIO,
  23800. + MISSED_TIMER_OFFSETS,
  23801. + TIMERANDWAKEUP_LATENCY,
  23802. + MAX_LATENCY_TYPE,
  23803. +};
  23804. +
  23805. +#define MAX_ENTRY_NUM 10240
  23806. +
  23807. +struct hist_data {
  23808. + atomic_t hist_mode; /* 0 log, 1 don't log */
  23809. + long offset; /* set it to MAX_ENTRY_NUM/2 for a bipolar scale */
  23810. + long min_lat;
  23811. + long max_lat;
  23812. + unsigned long long below_hist_bound_samples;
  23813. + unsigned long long above_hist_bound_samples;
  23814. + long long accumulate_lat;
  23815. + unsigned long long total_samples;
  23816. + unsigned long long hist_array[MAX_ENTRY_NUM];
  23817. +};
  23818. +
  23819. +struct enable_data {
  23820. + int latency_type;
  23821. + int enabled;
  23822. +};
  23823. +
  23824. +static char *latency_hist_dir_root = "latency_hist";
  23825. +
  23826. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  23827. +static DEFINE_PER_CPU(struct hist_data, irqsoff_hist);
  23828. +static char *irqsoff_hist_dir = "irqsoff";
  23829. +static DEFINE_PER_CPU(cycles_t, hist_irqsoff_start);
  23830. +static DEFINE_PER_CPU(int, hist_irqsoff_counting);
  23831. +#endif
  23832. +
  23833. +#ifdef CONFIG_PREEMPT_OFF_HIST
  23834. +static DEFINE_PER_CPU(struct hist_data, preemptoff_hist);
  23835. +static char *preemptoff_hist_dir = "preemptoff";
  23836. +static DEFINE_PER_CPU(cycles_t, hist_preemptoff_start);
  23837. +static DEFINE_PER_CPU(int, hist_preemptoff_counting);
  23838. +#endif
  23839. +
  23840. +#if defined(CONFIG_PREEMPT_OFF_HIST) && defined(CONFIG_INTERRUPT_OFF_HIST)
  23841. +static DEFINE_PER_CPU(struct hist_data, preemptirqsoff_hist);
  23842. +static char *preemptirqsoff_hist_dir = "preemptirqsoff";
  23843. +static DEFINE_PER_CPU(cycles_t, hist_preemptirqsoff_start);
  23844. +static DEFINE_PER_CPU(int, hist_preemptirqsoff_counting);
  23845. +#endif
  23846. +
  23847. +#if defined(CONFIG_PREEMPT_OFF_HIST) || defined(CONFIG_INTERRUPT_OFF_HIST)
  23848. +static notrace void probe_preemptirqsoff_hist(void *v, int reason, int start);
  23849. +static struct enable_data preemptirqsoff_enabled_data = {
  23850. + .latency_type = PREEMPTIRQSOFF_LATENCY,
  23851. + .enabled = 0,
  23852. +};
  23853. +#endif
  23854. +
  23855. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  23856. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  23857. +struct maxlatproc_data {
  23858. + char comm[FIELD_SIZEOF(struct task_struct, comm)];
  23859. + char current_comm[FIELD_SIZEOF(struct task_struct, comm)];
  23860. + int pid;
  23861. + int current_pid;
  23862. + int prio;
  23863. + int current_prio;
  23864. + long latency;
  23865. + long timeroffset;
  23866. + cycle_t timestamp;
  23867. +};
  23868. +#endif
  23869. +
  23870. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  23871. +static DEFINE_PER_CPU(struct hist_data, wakeup_latency_hist);
  23872. +static DEFINE_PER_CPU(struct hist_data, wakeup_latency_hist_sharedprio);
  23873. +static char *wakeup_latency_hist_dir = "wakeup";
  23874. +static char *wakeup_latency_hist_dir_sharedprio = "sharedprio";
  23875. +static notrace void probe_wakeup_latency_hist_start(void *v,
  23876. + struct task_struct *p);
  23877. +static notrace void probe_wakeup_latency_hist_stop(void *v,
  23878. + bool preempt, struct task_struct *prev, struct task_struct *next);
  23879. +static notrace void probe_sched_migrate_task(void *,
  23880. + struct task_struct *task, int cpu);
  23881. +static struct enable_data wakeup_latency_enabled_data = {
  23882. + .latency_type = WAKEUP_LATENCY,
  23883. + .enabled = 0,
  23884. +};
  23885. +static DEFINE_PER_CPU(struct maxlatproc_data, wakeup_maxlatproc);
  23886. +static DEFINE_PER_CPU(struct maxlatproc_data, wakeup_maxlatproc_sharedprio);
  23887. +static DEFINE_PER_CPU(struct task_struct *, wakeup_task);
  23888. +static DEFINE_PER_CPU(int, wakeup_sharedprio);
  23889. +static unsigned long wakeup_pid;
  23890. +#endif
  23891. +
  23892. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  23893. +static DEFINE_PER_CPU(struct hist_data, missed_timer_offsets);
  23894. +static char *missed_timer_offsets_dir = "missed_timer_offsets";
  23895. +static notrace void probe_hrtimer_interrupt(void *v, int cpu,
  23896. + long long offset, struct task_struct *curr, struct task_struct *task);
  23897. +static struct enable_data missed_timer_offsets_enabled_data = {
  23898. + .latency_type = MISSED_TIMER_OFFSETS,
  23899. + .enabled = 0,
  23900. +};
  23901. +static DEFINE_PER_CPU(struct maxlatproc_data, missed_timer_offsets_maxlatproc);
  23902. +static unsigned long missed_timer_offsets_pid;
  23903. +#endif
  23904. +
  23905. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  23906. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  23907. +static DEFINE_PER_CPU(struct hist_data, timerandwakeup_latency_hist);
  23908. +static char *timerandwakeup_latency_hist_dir = "timerandwakeup";
  23909. +static struct enable_data timerandwakeup_enabled_data = {
  23910. + .latency_type = TIMERANDWAKEUP_LATENCY,
  23911. + .enabled = 0,
  23912. +};
  23913. +static DEFINE_PER_CPU(struct maxlatproc_data, timerandwakeup_maxlatproc);
  23914. +#endif
  23915. +
  23916. +void notrace latency_hist(int latency_type, int cpu, long latency,
  23917. + long timeroffset, cycle_t stop,
  23918. + struct task_struct *p)
  23919. +{
  23920. + struct hist_data *my_hist;
  23921. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  23922. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  23923. + struct maxlatproc_data *mp = NULL;
  23924. +#endif
  23925. +
  23926. + if (!cpu_possible(cpu) || latency_type < 0 ||
  23927. + latency_type >= MAX_LATENCY_TYPE)
  23928. + return;
  23929. +
  23930. + switch (latency_type) {
  23931. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  23932. + case IRQSOFF_LATENCY:
  23933. + my_hist = &per_cpu(irqsoff_hist, cpu);
  23934. + break;
  23935. +#endif
  23936. +#ifdef CONFIG_PREEMPT_OFF_HIST
  23937. + case PREEMPTOFF_LATENCY:
  23938. + my_hist = &per_cpu(preemptoff_hist, cpu);
  23939. + break;
  23940. +#endif
  23941. +#if defined(CONFIG_PREEMPT_OFF_HIST) && defined(CONFIG_INTERRUPT_OFF_HIST)
  23942. + case PREEMPTIRQSOFF_LATENCY:
  23943. + my_hist = &per_cpu(preemptirqsoff_hist, cpu);
  23944. + break;
  23945. +#endif
  23946. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  23947. + case WAKEUP_LATENCY:
  23948. + my_hist = &per_cpu(wakeup_latency_hist, cpu);
  23949. + mp = &per_cpu(wakeup_maxlatproc, cpu);
  23950. + break;
  23951. + case WAKEUP_LATENCY_SHAREDPRIO:
  23952. + my_hist = &per_cpu(wakeup_latency_hist_sharedprio, cpu);
  23953. + mp = &per_cpu(wakeup_maxlatproc_sharedprio, cpu);
  23954. + break;
  23955. +#endif
  23956. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  23957. + case MISSED_TIMER_OFFSETS:
  23958. + my_hist = &per_cpu(missed_timer_offsets, cpu);
  23959. + mp = &per_cpu(missed_timer_offsets_maxlatproc, cpu);
  23960. + break;
  23961. +#endif
  23962. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  23963. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  23964. + case TIMERANDWAKEUP_LATENCY:
  23965. + my_hist = &per_cpu(timerandwakeup_latency_hist, cpu);
  23966. + mp = &per_cpu(timerandwakeup_maxlatproc, cpu);
  23967. + break;
  23968. +#endif
  23969. +
  23970. + default:
  23971. + return;
  23972. + }
  23973. +
  23974. + latency += my_hist->offset;
  23975. +
  23976. + if (atomic_read(&my_hist->hist_mode) == 0)
  23977. + return;
  23978. +
  23979. + if (latency < 0 || latency >= MAX_ENTRY_NUM) {
  23980. + if (latency < 0)
  23981. + my_hist->below_hist_bound_samples++;
  23982. + else
  23983. + my_hist->above_hist_bound_samples++;
  23984. + } else
  23985. + my_hist->hist_array[latency]++;
  23986. +
  23987. + if (unlikely(latency > my_hist->max_lat ||
  23988. + my_hist->min_lat == LONG_MAX)) {
  23989. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  23990. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  23991. + if (latency_type == WAKEUP_LATENCY ||
  23992. + latency_type == WAKEUP_LATENCY_SHAREDPRIO ||
  23993. + latency_type == MISSED_TIMER_OFFSETS ||
  23994. + latency_type == TIMERANDWAKEUP_LATENCY) {
  23995. + strncpy(mp->comm, p->comm, sizeof(mp->comm));
  23996. + strncpy(mp->current_comm, current->comm,
  23997. + sizeof(mp->current_comm));
  23998. + mp->pid = task_pid_nr(p);
  23999. + mp->current_pid = task_pid_nr(current);
  24000. + mp->prio = p->prio;
  24001. + mp->current_prio = current->prio;
  24002. + mp->latency = latency;
  24003. + mp->timeroffset = timeroffset;
  24004. + mp->timestamp = stop;
  24005. + }
  24006. +#endif
  24007. + my_hist->max_lat = latency;
  24008. + }
  24009. + if (unlikely(latency < my_hist->min_lat))
  24010. + my_hist->min_lat = latency;
  24011. + my_hist->total_samples++;
  24012. + my_hist->accumulate_lat += latency;
  24013. +}
  24014. +
  24015. +static void *l_start(struct seq_file *m, loff_t *pos)
  24016. +{
  24017. + loff_t *index_ptr = NULL;
  24018. + loff_t index = *pos;
  24019. + struct hist_data *my_hist = m->private;
  24020. +
  24021. + if (index == 0) {
  24022. + char minstr[32], avgstr[32], maxstr[32];
  24023. +
  24024. + atomic_dec(&my_hist->hist_mode);
  24025. +
  24026. + if (likely(my_hist->total_samples)) {
  24027. + long avg = (long) div64_s64(my_hist->accumulate_lat,
  24028. + my_hist->total_samples);
  24029. + snprintf(minstr, sizeof(minstr), "%ld",
  24030. + my_hist->min_lat - my_hist->offset);
  24031. + snprintf(avgstr, sizeof(avgstr), "%ld",
  24032. + avg - my_hist->offset);
  24033. + snprintf(maxstr, sizeof(maxstr), "%ld",
  24034. + my_hist->max_lat - my_hist->offset);
  24035. + } else {
  24036. + strcpy(minstr, "<undef>");
  24037. + strcpy(avgstr, minstr);
  24038. + strcpy(maxstr, minstr);
  24039. + }
  24040. +
  24041. + seq_printf(m, "#Minimum latency: %s microseconds\n"
  24042. + "#Average latency: %s microseconds\n"
  24043. + "#Maximum latency: %s microseconds\n"
  24044. + "#Total samples: %llu\n"
  24045. + "#There are %llu samples lower than %ld"
  24046. + " microseconds.\n"
  24047. + "#There are %llu samples greater or equal"
  24048. + " than %ld microseconds.\n"
  24049. + "#usecs\t%16s\n",
  24050. + minstr, avgstr, maxstr,
  24051. + my_hist->total_samples,
  24052. + my_hist->below_hist_bound_samples,
  24053. + -my_hist->offset,
  24054. + my_hist->above_hist_bound_samples,
  24055. + MAX_ENTRY_NUM - my_hist->offset,
  24056. + "samples");
  24057. + }
  24058. + if (index < MAX_ENTRY_NUM) {
  24059. + index_ptr = kmalloc(sizeof(loff_t), GFP_KERNEL);
  24060. + if (index_ptr)
  24061. + *index_ptr = index;
  24062. + }
  24063. +
  24064. + return index_ptr;
  24065. +}
  24066. +
  24067. +static void *l_next(struct seq_file *m, void *p, loff_t *pos)
  24068. +{
  24069. + loff_t *index_ptr = p;
  24070. + struct hist_data *my_hist = m->private;
  24071. +
  24072. + if (++*pos >= MAX_ENTRY_NUM) {
  24073. + atomic_inc(&my_hist->hist_mode);
  24074. + return NULL;
  24075. + }
  24076. + *index_ptr = *pos;
  24077. + return index_ptr;
  24078. +}
  24079. +
  24080. +static void l_stop(struct seq_file *m, void *p)
  24081. +{
  24082. + kfree(p);
  24083. +}
  24084. +
  24085. +static int l_show(struct seq_file *m, void *p)
  24086. +{
  24087. + int index = *(loff_t *) p;
  24088. + struct hist_data *my_hist = m->private;
  24089. +
  24090. + seq_printf(m, "%6ld\t%16llu\n", index - my_hist->offset,
  24091. + my_hist->hist_array[index]);
  24092. + return 0;
  24093. +}
  24094. +
  24095. +static const struct seq_operations latency_hist_seq_op = {
  24096. + .start = l_start,
  24097. + .next = l_next,
  24098. + .stop = l_stop,
  24099. + .show = l_show
  24100. +};
  24101. +
  24102. +static int latency_hist_open(struct inode *inode, struct file *file)
  24103. +{
  24104. + int ret;
  24105. +
  24106. + ret = seq_open(file, &latency_hist_seq_op);
  24107. + if (!ret) {
  24108. + struct seq_file *seq = file->private_data;
  24109. + seq->private = inode->i_private;
  24110. + }
  24111. + return ret;
  24112. +}
  24113. +
  24114. +static const struct file_operations latency_hist_fops = {
  24115. + .open = latency_hist_open,
  24116. + .read = seq_read,
  24117. + .llseek = seq_lseek,
  24118. + .release = seq_release,
  24119. +};
  24120. +
  24121. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  24122. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  24123. +static void clear_maxlatprocdata(struct maxlatproc_data *mp)
  24124. +{
  24125. + mp->comm[0] = mp->current_comm[0] = '\0';
  24126. + mp->prio = mp->current_prio = mp->pid = mp->current_pid =
  24127. + mp->latency = mp->timeroffset = -1;
  24128. + mp->timestamp = 0;
  24129. +}
  24130. +#endif
  24131. +
  24132. +static void hist_reset(struct hist_data *hist)
  24133. +{
  24134. + atomic_dec(&hist->hist_mode);
  24135. +
  24136. + memset(hist->hist_array, 0, sizeof(hist->hist_array));
  24137. + hist->below_hist_bound_samples = 0ULL;
  24138. + hist->above_hist_bound_samples = 0ULL;
  24139. + hist->min_lat = LONG_MAX;
  24140. + hist->max_lat = LONG_MIN;
  24141. + hist->total_samples = 0ULL;
  24142. + hist->accumulate_lat = 0LL;
  24143. +
  24144. + atomic_inc(&hist->hist_mode);
  24145. +}
  24146. +
  24147. +static ssize_t
  24148. +latency_hist_reset(struct file *file, const char __user *a,
  24149. + size_t size, loff_t *off)
  24150. +{
  24151. + int cpu;
  24152. + struct hist_data *hist = NULL;
  24153. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  24154. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  24155. + struct maxlatproc_data *mp = NULL;
  24156. +#endif
  24157. + off_t latency_type = (off_t) file->private_data;
  24158. +
  24159. + for_each_online_cpu(cpu) {
  24160. +
  24161. + switch (latency_type) {
  24162. +#ifdef CONFIG_PREEMPT_OFF_HIST
  24163. + case PREEMPTOFF_LATENCY:
  24164. + hist = &per_cpu(preemptoff_hist, cpu);
  24165. + break;
  24166. +#endif
  24167. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  24168. + case IRQSOFF_LATENCY:
  24169. + hist = &per_cpu(irqsoff_hist, cpu);
  24170. + break;
  24171. +#endif
  24172. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  24173. + case PREEMPTIRQSOFF_LATENCY:
  24174. + hist = &per_cpu(preemptirqsoff_hist, cpu);
  24175. + break;
  24176. +#endif
  24177. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  24178. + case WAKEUP_LATENCY:
  24179. + hist = &per_cpu(wakeup_latency_hist, cpu);
  24180. + mp = &per_cpu(wakeup_maxlatproc, cpu);
  24181. + break;
  24182. + case WAKEUP_LATENCY_SHAREDPRIO:
  24183. + hist = &per_cpu(wakeup_latency_hist_sharedprio, cpu);
  24184. + mp = &per_cpu(wakeup_maxlatproc_sharedprio, cpu);
  24185. + break;
  24186. +#endif
  24187. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  24188. + case MISSED_TIMER_OFFSETS:
  24189. + hist = &per_cpu(missed_timer_offsets, cpu);
  24190. + mp = &per_cpu(missed_timer_offsets_maxlatproc, cpu);
  24191. + break;
  24192. +#endif
  24193. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  24194. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  24195. + case TIMERANDWAKEUP_LATENCY:
  24196. + hist = &per_cpu(timerandwakeup_latency_hist, cpu);
  24197. + mp = &per_cpu(timerandwakeup_maxlatproc, cpu);
  24198. + break;
  24199. +#endif
  24200. + }
  24201. +
  24202. + hist_reset(hist);
  24203. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  24204. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  24205. + if (latency_type == WAKEUP_LATENCY ||
  24206. + latency_type == WAKEUP_LATENCY_SHAREDPRIO ||
  24207. + latency_type == MISSED_TIMER_OFFSETS ||
  24208. + latency_type == TIMERANDWAKEUP_LATENCY)
  24209. + clear_maxlatprocdata(mp);
  24210. +#endif
  24211. + }
  24212. +
  24213. + return size;
  24214. +}
  24215. +
  24216. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  24217. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  24218. +static ssize_t
  24219. +show_pid(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
  24220. +{
  24221. + char buf[64];
  24222. + int r;
  24223. + unsigned long *this_pid = file->private_data;
  24224. +
  24225. + r = snprintf(buf, sizeof(buf), "%lu\n", *this_pid);
  24226. + return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  24227. +}
  24228. +
  24229. +static ssize_t do_pid(struct file *file, const char __user *ubuf,
  24230. + size_t cnt, loff_t *ppos)
  24231. +{
  24232. + char buf[64];
  24233. + unsigned long pid;
  24234. + unsigned long *this_pid = file->private_data;
  24235. +
  24236. + if (cnt >= sizeof(buf))
  24237. + return -EINVAL;
  24238. +
  24239. + if (copy_from_user(&buf, ubuf, cnt))
  24240. + return -EFAULT;
  24241. +
  24242. + buf[cnt] = '\0';
  24243. +
  24244. + if (kstrtoul(buf, 10, &pid))
  24245. + return -EINVAL;
  24246. +
  24247. + *this_pid = pid;
  24248. +
  24249. + return cnt;
  24250. +}
  24251. +#endif
  24252. +
  24253. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  24254. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  24255. +static ssize_t
  24256. +show_maxlatproc(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
  24257. +{
  24258. + int r;
  24259. + struct maxlatproc_data *mp = file->private_data;
  24260. + int strmaxlen = (TASK_COMM_LEN * 2) + (8 * 8);
  24261. + unsigned long long t;
  24262. + unsigned long usecs, secs;
  24263. + char *buf;
  24264. +
  24265. + if (mp->pid == -1 || mp->current_pid == -1) {
  24266. + buf = "(none)\n";
  24267. + return simple_read_from_buffer(ubuf, cnt, ppos, buf,
  24268. + strlen(buf));
  24269. + }
  24270. +
  24271. + buf = kmalloc(strmaxlen, GFP_KERNEL);
  24272. + if (buf == NULL)
  24273. + return -ENOMEM;
  24274. +
  24275. + t = ns2usecs(mp->timestamp);
  24276. + usecs = do_div(t, USEC_PER_SEC);
  24277. + secs = (unsigned long) t;
  24278. + r = snprintf(buf, strmaxlen,
  24279. + "%d %d %ld (%ld) %s <- %d %d %s %lu.%06lu\n", mp->pid,
  24280. + MAX_RT_PRIO-1 - mp->prio, mp->latency, mp->timeroffset, mp->comm,
  24281. + mp->current_pid, MAX_RT_PRIO-1 - mp->current_prio, mp->current_comm,
  24282. + secs, usecs);
  24283. + r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  24284. + kfree(buf);
  24285. + return r;
  24286. +}
  24287. +#endif
  24288. +
  24289. +static ssize_t
  24290. +show_enable(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
  24291. +{
  24292. + char buf[64];
  24293. + struct enable_data *ed = file->private_data;
  24294. + int r;
  24295. +
  24296. + r = snprintf(buf, sizeof(buf), "%d\n", ed->enabled);
  24297. + return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  24298. +}
  24299. +
  24300. +static ssize_t
  24301. +do_enable(struct file *file, const char __user *ubuf, size_t cnt, loff_t *ppos)
  24302. +{
  24303. + char buf[64];
  24304. + long enable;
  24305. + struct enable_data *ed = file->private_data;
  24306. +
  24307. + if (cnt >= sizeof(buf))
  24308. + return -EINVAL;
  24309. +
  24310. + if (copy_from_user(&buf, ubuf, cnt))
  24311. + return -EFAULT;
  24312. +
  24313. + buf[cnt] = 0;
  24314. +
  24315. + if (kstrtoul(buf, 10, &enable))
  24316. + return -EINVAL;
  24317. +
  24318. + if ((enable && ed->enabled) || (!enable && !ed->enabled))
  24319. + return cnt;
  24320. +
  24321. + if (enable) {
  24322. + int ret;
  24323. +
  24324. + switch (ed->latency_type) {
  24325. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  24326. + case PREEMPTIRQSOFF_LATENCY:
  24327. + ret = register_trace_preemptirqsoff_hist(
  24328. + probe_preemptirqsoff_hist, NULL);
  24329. + if (ret) {
  24330. + pr_info("wakeup trace: Couldn't assign "
  24331. + "probe_preemptirqsoff_hist "
  24332. + "to trace_preemptirqsoff_hist\n");
  24333. + return ret;
  24334. + }
  24335. + break;
  24336. +#endif
  24337. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  24338. + case WAKEUP_LATENCY:
  24339. + ret = register_trace_sched_wakeup(
  24340. + probe_wakeup_latency_hist_start, NULL);
  24341. + if (ret) {
  24342. + pr_info("wakeup trace: Couldn't assign "
  24343. + "probe_wakeup_latency_hist_start "
  24344. + "to trace_sched_wakeup\n");
  24345. + return ret;
  24346. + }
  24347. + ret = register_trace_sched_wakeup_new(
  24348. + probe_wakeup_latency_hist_start, NULL);
  24349. + if (ret) {
  24350. + pr_info("wakeup trace: Couldn't assign "
  24351. + "probe_wakeup_latency_hist_start "
  24352. + "to trace_sched_wakeup_new\n");
  24353. + unregister_trace_sched_wakeup(
  24354. + probe_wakeup_latency_hist_start, NULL);
  24355. + return ret;
  24356. + }
  24357. + ret = register_trace_sched_switch(
  24358. + probe_wakeup_latency_hist_stop, NULL);
  24359. + if (ret) {
  24360. + pr_info("wakeup trace: Couldn't assign "
  24361. + "probe_wakeup_latency_hist_stop "
  24362. + "to trace_sched_switch\n");
  24363. + unregister_trace_sched_wakeup(
  24364. + probe_wakeup_latency_hist_start, NULL);
  24365. + unregister_trace_sched_wakeup_new(
  24366. + probe_wakeup_latency_hist_start, NULL);
  24367. + return ret;
  24368. + }
  24369. + ret = register_trace_sched_migrate_task(
  24370. + probe_sched_migrate_task, NULL);
  24371. + if (ret) {
  24372. + pr_info("wakeup trace: Couldn't assign "
  24373. + "probe_sched_migrate_task "
  24374. + "to trace_sched_migrate_task\n");
  24375. + unregister_trace_sched_wakeup(
  24376. + probe_wakeup_latency_hist_start, NULL);
  24377. + unregister_trace_sched_wakeup_new(
  24378. + probe_wakeup_latency_hist_start, NULL);
  24379. + unregister_trace_sched_switch(
  24380. + probe_wakeup_latency_hist_stop, NULL);
  24381. + return ret;
  24382. + }
  24383. + break;
  24384. +#endif
  24385. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  24386. + case MISSED_TIMER_OFFSETS:
  24387. + ret = register_trace_hrtimer_interrupt(
  24388. + probe_hrtimer_interrupt, NULL);
  24389. + if (ret) {
  24390. + pr_info("wakeup trace: Couldn't assign "
  24391. + "probe_hrtimer_interrupt "
  24392. + "to trace_hrtimer_interrupt\n");
  24393. + return ret;
  24394. + }
  24395. + break;
  24396. +#endif
  24397. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  24398. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  24399. + case TIMERANDWAKEUP_LATENCY:
  24400. + if (!wakeup_latency_enabled_data.enabled ||
  24401. + !missed_timer_offsets_enabled_data.enabled)
  24402. + return -EINVAL;
  24403. + break;
  24404. +#endif
  24405. + default:
  24406. + break;
  24407. + }
  24408. + } else {
  24409. + switch (ed->latency_type) {
  24410. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  24411. + case PREEMPTIRQSOFF_LATENCY:
  24412. + {
  24413. + int cpu;
  24414. +
  24415. + unregister_trace_preemptirqsoff_hist(
  24416. + probe_preemptirqsoff_hist, NULL);
  24417. + for_each_online_cpu(cpu) {
  24418. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  24419. + per_cpu(hist_irqsoff_counting,
  24420. + cpu) = 0;
  24421. +#endif
  24422. +#ifdef CONFIG_PREEMPT_OFF_HIST
  24423. + per_cpu(hist_preemptoff_counting,
  24424. + cpu) = 0;
  24425. +#endif
  24426. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  24427. + per_cpu(hist_preemptirqsoff_counting,
  24428. + cpu) = 0;
  24429. +#endif
  24430. + }
  24431. + }
  24432. + break;
  24433. +#endif
  24434. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  24435. + case WAKEUP_LATENCY:
  24436. + {
  24437. + int cpu;
  24438. +
  24439. + unregister_trace_sched_wakeup(
  24440. + probe_wakeup_latency_hist_start, NULL);
  24441. + unregister_trace_sched_wakeup_new(
  24442. + probe_wakeup_latency_hist_start, NULL);
  24443. + unregister_trace_sched_switch(
  24444. + probe_wakeup_latency_hist_stop, NULL);
  24445. + unregister_trace_sched_migrate_task(
  24446. + probe_sched_migrate_task, NULL);
  24447. +
  24448. + for_each_online_cpu(cpu) {
  24449. + per_cpu(wakeup_task, cpu) = NULL;
  24450. + per_cpu(wakeup_sharedprio, cpu) = 0;
  24451. + }
  24452. + }
  24453. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  24454. + timerandwakeup_enabled_data.enabled = 0;
  24455. +#endif
  24456. + break;
  24457. +#endif
  24458. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  24459. + case MISSED_TIMER_OFFSETS:
  24460. + unregister_trace_hrtimer_interrupt(
  24461. + probe_hrtimer_interrupt, NULL);
  24462. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  24463. + timerandwakeup_enabled_data.enabled = 0;
  24464. +#endif
  24465. + break;
  24466. +#endif
  24467. + default:
  24468. + break;
  24469. + }
  24470. + }
  24471. + ed->enabled = enable;
  24472. + return cnt;
  24473. +}
  24474. +
  24475. +static const struct file_operations latency_hist_reset_fops = {
  24476. + .open = tracing_open_generic,
  24477. + .write = latency_hist_reset,
  24478. +};
  24479. +
  24480. +static const struct file_operations enable_fops = {
  24481. + .open = tracing_open_generic,
  24482. + .read = show_enable,
  24483. + .write = do_enable,
  24484. +};
  24485. +
  24486. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  24487. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  24488. +static const struct file_operations pid_fops = {
  24489. + .open = tracing_open_generic,
  24490. + .read = show_pid,
  24491. + .write = do_pid,
  24492. +};
  24493. +
  24494. +static const struct file_operations maxlatproc_fops = {
  24495. + .open = tracing_open_generic,
  24496. + .read = show_maxlatproc,
  24497. +};
  24498. +#endif
  24499. +
  24500. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  24501. +static notrace void probe_preemptirqsoff_hist(void *v, int reason,
  24502. + int starthist)
  24503. +{
  24504. + int cpu = raw_smp_processor_id();
  24505. + int time_set = 0;
  24506. +
  24507. + if (starthist) {
  24508. + cycle_t uninitialized_var(start);
  24509. +
  24510. + if (!preempt_count() && !irqs_disabled())
  24511. + return;
  24512. +
  24513. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  24514. + if ((reason == IRQS_OFF || reason == TRACE_START) &&
  24515. + !per_cpu(hist_irqsoff_counting, cpu)) {
  24516. + per_cpu(hist_irqsoff_counting, cpu) = 1;
  24517. + start = ftrace_now(cpu);
  24518. + time_set++;
  24519. + per_cpu(hist_irqsoff_start, cpu) = start;
  24520. + }
  24521. +#endif
  24522. +
  24523. +#ifdef CONFIG_PREEMPT_OFF_HIST
  24524. + if ((reason == PREEMPT_OFF || reason == TRACE_START) &&
  24525. + !per_cpu(hist_preemptoff_counting, cpu)) {
  24526. + per_cpu(hist_preemptoff_counting, cpu) = 1;
  24527. + if (!(time_set++))
  24528. + start = ftrace_now(cpu);
  24529. + per_cpu(hist_preemptoff_start, cpu) = start;
  24530. + }
  24531. +#endif
  24532. +
  24533. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  24534. + if (per_cpu(hist_irqsoff_counting, cpu) &&
  24535. + per_cpu(hist_preemptoff_counting, cpu) &&
  24536. + !per_cpu(hist_preemptirqsoff_counting, cpu)) {
  24537. + per_cpu(hist_preemptirqsoff_counting, cpu) = 1;
  24538. + if (!time_set)
  24539. + start = ftrace_now(cpu);
  24540. + per_cpu(hist_preemptirqsoff_start, cpu) = start;
  24541. + }
  24542. +#endif
  24543. + } else {
  24544. + cycle_t uninitialized_var(stop);
  24545. +
  24546. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  24547. + if ((reason == IRQS_ON || reason == TRACE_STOP) &&
  24548. + per_cpu(hist_irqsoff_counting, cpu)) {
  24549. + cycle_t start = per_cpu(hist_irqsoff_start, cpu);
  24550. +
  24551. + stop = ftrace_now(cpu);
  24552. + time_set++;
  24553. + if (start) {
  24554. + long latency = ((long) (stop - start)) /
  24555. + NSECS_PER_USECS;
  24556. +
  24557. + latency_hist(IRQSOFF_LATENCY, cpu, latency, 0,
  24558. + stop, NULL);
  24559. + }
  24560. + per_cpu(hist_irqsoff_counting, cpu) = 0;
  24561. + }
  24562. +#endif
  24563. +
  24564. +#ifdef CONFIG_PREEMPT_OFF_HIST
  24565. + if ((reason == PREEMPT_ON || reason == TRACE_STOP) &&
  24566. + per_cpu(hist_preemptoff_counting, cpu)) {
  24567. + cycle_t start = per_cpu(hist_preemptoff_start, cpu);
  24568. +
  24569. + if (!(time_set++))
  24570. + stop = ftrace_now(cpu);
  24571. + if (start) {
  24572. + long latency = ((long) (stop - start)) /
  24573. + NSECS_PER_USECS;
  24574. +
  24575. + latency_hist(PREEMPTOFF_LATENCY, cpu, latency,
  24576. + 0, stop, NULL);
  24577. + }
  24578. + per_cpu(hist_preemptoff_counting, cpu) = 0;
  24579. + }
  24580. +#endif
  24581. +
  24582. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  24583. + if ((!per_cpu(hist_irqsoff_counting, cpu) ||
  24584. + !per_cpu(hist_preemptoff_counting, cpu)) &&
  24585. + per_cpu(hist_preemptirqsoff_counting, cpu)) {
  24586. + cycle_t start = per_cpu(hist_preemptirqsoff_start, cpu);
  24587. +
  24588. + if (!time_set)
  24589. + stop = ftrace_now(cpu);
  24590. + if (start) {
  24591. + long latency = ((long) (stop - start)) /
  24592. + NSECS_PER_USECS;
  24593. +
  24594. + latency_hist(PREEMPTIRQSOFF_LATENCY, cpu,
  24595. + latency, 0, stop, NULL);
  24596. + }
  24597. + per_cpu(hist_preemptirqsoff_counting, cpu) = 0;
  24598. + }
  24599. +#endif
  24600. + }
  24601. +}
  24602. +#endif
  24603. +
  24604. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  24605. +static DEFINE_RAW_SPINLOCK(wakeup_lock);
  24606. +static notrace void probe_sched_migrate_task(void *v, struct task_struct *task,
  24607. + int cpu)
  24608. +{
  24609. + int old_cpu = task_cpu(task);
  24610. +
  24611. + if (cpu != old_cpu) {
  24612. + unsigned long flags;
  24613. + struct task_struct *cpu_wakeup_task;
  24614. +
  24615. + raw_spin_lock_irqsave(&wakeup_lock, flags);
  24616. +
  24617. + cpu_wakeup_task = per_cpu(wakeup_task, old_cpu);
  24618. + if (task == cpu_wakeup_task) {
  24619. + put_task_struct(cpu_wakeup_task);
  24620. + per_cpu(wakeup_task, old_cpu) = NULL;
  24621. + cpu_wakeup_task = per_cpu(wakeup_task, cpu) = task;
  24622. + get_task_struct(cpu_wakeup_task);
  24623. + }
  24624. +
  24625. + raw_spin_unlock_irqrestore(&wakeup_lock, flags);
  24626. + }
  24627. +}
  24628. +
  24629. +static notrace void probe_wakeup_latency_hist_start(void *v,
  24630. + struct task_struct *p)
  24631. +{
  24632. + unsigned long flags;
  24633. + struct task_struct *curr = current;
  24634. + int cpu = task_cpu(p);
  24635. + struct task_struct *cpu_wakeup_task;
  24636. +
  24637. + raw_spin_lock_irqsave(&wakeup_lock, flags);
  24638. +
  24639. + cpu_wakeup_task = per_cpu(wakeup_task, cpu);
  24640. +
  24641. + if (wakeup_pid) {
  24642. + if ((cpu_wakeup_task && p->prio == cpu_wakeup_task->prio) ||
  24643. + p->prio == curr->prio)
  24644. + per_cpu(wakeup_sharedprio, cpu) = 1;
  24645. + if (likely(wakeup_pid != task_pid_nr(p)))
  24646. + goto out;
  24647. + } else {
  24648. + if (likely(!rt_task(p)) ||
  24649. + (cpu_wakeup_task && p->prio > cpu_wakeup_task->prio) ||
  24650. + p->prio > curr->prio)
  24651. + goto out;
  24652. + if ((cpu_wakeup_task && p->prio == cpu_wakeup_task->prio) ||
  24653. + p->prio == curr->prio)
  24654. + per_cpu(wakeup_sharedprio, cpu) = 1;
  24655. + }
  24656. +
  24657. + if (cpu_wakeup_task)
  24658. + put_task_struct(cpu_wakeup_task);
  24659. + cpu_wakeup_task = per_cpu(wakeup_task, cpu) = p;
  24660. + get_task_struct(cpu_wakeup_task);
  24661. + cpu_wakeup_task->preempt_timestamp_hist =
  24662. + ftrace_now(raw_smp_processor_id());
  24663. +out:
  24664. + raw_spin_unlock_irqrestore(&wakeup_lock, flags);
  24665. +}
  24666. +
  24667. +static notrace void probe_wakeup_latency_hist_stop(void *v,
  24668. + bool preempt, struct task_struct *prev, struct task_struct *next)
  24669. +{
  24670. + unsigned long flags;
  24671. + int cpu = task_cpu(next);
  24672. + long latency;
  24673. + cycle_t stop;
  24674. + struct task_struct *cpu_wakeup_task;
  24675. +
  24676. + raw_spin_lock_irqsave(&wakeup_lock, flags);
  24677. +
  24678. + cpu_wakeup_task = per_cpu(wakeup_task, cpu);
  24679. +
  24680. + if (cpu_wakeup_task == NULL)
  24681. + goto out;
  24682. +
  24683. + /* Already running? */
  24684. + if (unlikely(current == cpu_wakeup_task))
  24685. + goto out_reset;
  24686. +
  24687. + if (next != cpu_wakeup_task) {
  24688. + if (next->prio < cpu_wakeup_task->prio)
  24689. + goto out_reset;
  24690. +
  24691. + if (next->prio == cpu_wakeup_task->prio)
  24692. + per_cpu(wakeup_sharedprio, cpu) = 1;
  24693. +
  24694. + goto out;
  24695. + }
  24696. +
  24697. + if (current->prio == cpu_wakeup_task->prio)
  24698. + per_cpu(wakeup_sharedprio, cpu) = 1;
  24699. +
  24700. + /*
  24701. + * The task we are waiting for is about to be switched to.
  24702. + * Calculate latency and store it in histogram.
  24703. + */
  24704. + stop = ftrace_now(raw_smp_processor_id());
  24705. +
  24706. + latency = ((long) (stop - next->preempt_timestamp_hist)) /
  24707. + NSECS_PER_USECS;
  24708. +
  24709. + if (per_cpu(wakeup_sharedprio, cpu)) {
  24710. + latency_hist(WAKEUP_LATENCY_SHAREDPRIO, cpu, latency, 0, stop,
  24711. + next);
  24712. + per_cpu(wakeup_sharedprio, cpu) = 0;
  24713. + } else {
  24714. + latency_hist(WAKEUP_LATENCY, cpu, latency, 0, stop, next);
  24715. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  24716. + if (timerandwakeup_enabled_data.enabled) {
  24717. + latency_hist(TIMERANDWAKEUP_LATENCY, cpu,
  24718. + next->timer_offset + latency, next->timer_offset,
  24719. + stop, next);
  24720. + }
  24721. +#endif
  24722. + }
  24723. +
  24724. +out_reset:
  24725. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  24726. + next->timer_offset = 0;
  24727. +#endif
  24728. + put_task_struct(cpu_wakeup_task);
  24729. + per_cpu(wakeup_task, cpu) = NULL;
  24730. +out:
  24731. + raw_spin_unlock_irqrestore(&wakeup_lock, flags);
  24732. +}
  24733. +#endif
  24734. +
  24735. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  24736. +static notrace void probe_hrtimer_interrupt(void *v, int cpu,
  24737. + long long latency_ns, struct task_struct *curr,
  24738. + struct task_struct *task)
  24739. +{
  24740. + if (latency_ns <= 0 && task != NULL && rt_task(task) &&
  24741. + (task->prio < curr->prio ||
  24742. + (task->prio == curr->prio &&
  24743. + !cpumask_test_cpu(cpu, &task->cpus_allowed)))) {
  24744. + long latency;
  24745. + cycle_t now;
  24746. +
  24747. + if (missed_timer_offsets_pid) {
  24748. + if (likely(missed_timer_offsets_pid !=
  24749. + task_pid_nr(task)))
  24750. + return;
  24751. + }
  24752. +
  24753. + now = ftrace_now(cpu);
  24754. + latency = (long) div_s64(-latency_ns, NSECS_PER_USECS);
  24755. + latency_hist(MISSED_TIMER_OFFSETS, cpu, latency, latency, now,
  24756. + task);
  24757. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  24758. + task->timer_offset = latency;
  24759. +#endif
  24760. + }
  24761. +}
  24762. +#endif
  24763. +
  24764. +static __init int latency_hist_init(void)
  24765. +{
  24766. + struct dentry *latency_hist_root = NULL;
  24767. + struct dentry *dentry;
  24768. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  24769. + struct dentry *dentry_sharedprio;
  24770. +#endif
  24771. + struct dentry *entry;
  24772. + struct dentry *enable_root;
  24773. + int i = 0;
  24774. + struct hist_data *my_hist;
  24775. + char name[64];
  24776. + char *cpufmt = "CPU%d";
  24777. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  24778. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  24779. + char *cpufmt_maxlatproc = "max_latency-CPU%d";
  24780. + struct maxlatproc_data *mp = NULL;
  24781. +#endif
  24782. +
  24783. + dentry = tracing_init_dentry();
  24784. + latency_hist_root = debugfs_create_dir(latency_hist_dir_root, dentry);
  24785. + enable_root = debugfs_create_dir("enable", latency_hist_root);
  24786. +
  24787. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  24788. + dentry = debugfs_create_dir(irqsoff_hist_dir, latency_hist_root);
  24789. + for_each_possible_cpu(i) {
  24790. + sprintf(name, cpufmt, i);
  24791. + entry = debugfs_create_file(name, 0444, dentry,
  24792. + &per_cpu(irqsoff_hist, i), &latency_hist_fops);
  24793. + my_hist = &per_cpu(irqsoff_hist, i);
  24794. + atomic_set(&my_hist->hist_mode, 1);
  24795. + my_hist->min_lat = LONG_MAX;
  24796. + }
  24797. + entry = debugfs_create_file("reset", 0644, dentry,
  24798. + (void *)IRQSOFF_LATENCY, &latency_hist_reset_fops);
  24799. +#endif
  24800. +
  24801. +#ifdef CONFIG_PREEMPT_OFF_HIST
  24802. + dentry = debugfs_create_dir(preemptoff_hist_dir,
  24803. + latency_hist_root);
  24804. + for_each_possible_cpu(i) {
  24805. + sprintf(name, cpufmt, i);
  24806. + entry = debugfs_create_file(name, 0444, dentry,
  24807. + &per_cpu(preemptoff_hist, i), &latency_hist_fops);
  24808. + my_hist = &per_cpu(preemptoff_hist, i);
  24809. + atomic_set(&my_hist->hist_mode, 1);
  24810. + my_hist->min_lat = LONG_MAX;
  24811. + }
  24812. + entry = debugfs_create_file("reset", 0644, dentry,
  24813. + (void *)PREEMPTOFF_LATENCY, &latency_hist_reset_fops);
  24814. +#endif
  24815. +
  24816. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  24817. + dentry = debugfs_create_dir(preemptirqsoff_hist_dir,
  24818. + latency_hist_root);
  24819. + for_each_possible_cpu(i) {
  24820. + sprintf(name, cpufmt, i);
  24821. + entry = debugfs_create_file(name, 0444, dentry,
  24822. + &per_cpu(preemptirqsoff_hist, i), &latency_hist_fops);
  24823. + my_hist = &per_cpu(preemptirqsoff_hist, i);
  24824. + atomic_set(&my_hist->hist_mode, 1);
  24825. + my_hist->min_lat = LONG_MAX;
  24826. + }
  24827. + entry = debugfs_create_file("reset", 0644, dentry,
  24828. + (void *)PREEMPTIRQSOFF_LATENCY, &latency_hist_reset_fops);
  24829. +#endif
  24830. +
  24831. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  24832. + entry = debugfs_create_file("preemptirqsoff", 0644,
  24833. + enable_root, (void *)&preemptirqsoff_enabled_data,
  24834. + &enable_fops);
  24835. +#endif
  24836. +
  24837. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  24838. + dentry = debugfs_create_dir(wakeup_latency_hist_dir,
  24839. + latency_hist_root);
  24840. + dentry_sharedprio = debugfs_create_dir(
  24841. + wakeup_latency_hist_dir_sharedprio, dentry);
  24842. + for_each_possible_cpu(i) {
  24843. + sprintf(name, cpufmt, i);
  24844. +
  24845. + entry = debugfs_create_file(name, 0444, dentry,
  24846. + &per_cpu(wakeup_latency_hist, i),
  24847. + &latency_hist_fops);
  24848. + my_hist = &per_cpu(wakeup_latency_hist, i);
  24849. + atomic_set(&my_hist->hist_mode, 1);
  24850. + my_hist->min_lat = LONG_MAX;
  24851. +
  24852. + entry = debugfs_create_file(name, 0444, dentry_sharedprio,
  24853. + &per_cpu(wakeup_latency_hist_sharedprio, i),
  24854. + &latency_hist_fops);
  24855. + my_hist = &per_cpu(wakeup_latency_hist_sharedprio, i);
  24856. + atomic_set(&my_hist->hist_mode, 1);
  24857. + my_hist->min_lat = LONG_MAX;
  24858. +
  24859. + sprintf(name, cpufmt_maxlatproc, i);
  24860. +
  24861. + mp = &per_cpu(wakeup_maxlatproc, i);
  24862. + entry = debugfs_create_file(name, 0444, dentry, mp,
  24863. + &maxlatproc_fops);
  24864. + clear_maxlatprocdata(mp);
  24865. +
  24866. + mp = &per_cpu(wakeup_maxlatproc_sharedprio, i);
  24867. + entry = debugfs_create_file(name, 0444, dentry_sharedprio, mp,
  24868. + &maxlatproc_fops);
  24869. + clear_maxlatprocdata(mp);
  24870. + }
  24871. + entry = debugfs_create_file("pid", 0644, dentry,
  24872. + (void *)&wakeup_pid, &pid_fops);
  24873. + entry = debugfs_create_file("reset", 0644, dentry,
  24874. + (void *)WAKEUP_LATENCY, &latency_hist_reset_fops);
  24875. + entry = debugfs_create_file("reset", 0644, dentry_sharedprio,
  24876. + (void *)WAKEUP_LATENCY_SHAREDPRIO, &latency_hist_reset_fops);
  24877. + entry = debugfs_create_file("wakeup", 0644,
  24878. + enable_root, (void *)&wakeup_latency_enabled_data,
  24879. + &enable_fops);
  24880. +#endif
  24881. +
  24882. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  24883. + dentry = debugfs_create_dir(missed_timer_offsets_dir,
  24884. + latency_hist_root);
  24885. + for_each_possible_cpu(i) {
  24886. + sprintf(name, cpufmt, i);
  24887. + entry = debugfs_create_file(name, 0444, dentry,
  24888. + &per_cpu(missed_timer_offsets, i), &latency_hist_fops);
  24889. + my_hist = &per_cpu(missed_timer_offsets, i);
  24890. + atomic_set(&my_hist->hist_mode, 1);
  24891. + my_hist->min_lat = LONG_MAX;
  24892. +
  24893. + sprintf(name, cpufmt_maxlatproc, i);
  24894. + mp = &per_cpu(missed_timer_offsets_maxlatproc, i);
  24895. + entry = debugfs_create_file(name, 0444, dentry, mp,
  24896. + &maxlatproc_fops);
  24897. + clear_maxlatprocdata(mp);
  24898. + }
  24899. + entry = debugfs_create_file("pid", 0644, dentry,
  24900. + (void *)&missed_timer_offsets_pid, &pid_fops);
  24901. + entry = debugfs_create_file("reset", 0644, dentry,
  24902. + (void *)MISSED_TIMER_OFFSETS, &latency_hist_reset_fops);
  24903. + entry = debugfs_create_file("missed_timer_offsets", 0644,
  24904. + enable_root, (void *)&missed_timer_offsets_enabled_data,
  24905. + &enable_fops);
  24906. +#endif
  24907. +
  24908. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  24909. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  24910. + dentry = debugfs_create_dir(timerandwakeup_latency_hist_dir,
  24911. + latency_hist_root);
  24912. + for_each_possible_cpu(i) {
  24913. + sprintf(name, cpufmt, i);
  24914. + entry = debugfs_create_file(name, 0444, dentry,
  24915. + &per_cpu(timerandwakeup_latency_hist, i),
  24916. + &latency_hist_fops);
  24917. + my_hist = &per_cpu(timerandwakeup_latency_hist, i);
  24918. + atomic_set(&my_hist->hist_mode, 1);
  24919. + my_hist->min_lat = LONG_MAX;
  24920. +
  24921. + sprintf(name, cpufmt_maxlatproc, i);
  24922. + mp = &per_cpu(timerandwakeup_maxlatproc, i);
  24923. + entry = debugfs_create_file(name, 0444, dentry, mp,
  24924. + &maxlatproc_fops);
  24925. + clear_maxlatprocdata(mp);
  24926. + }
  24927. + entry = debugfs_create_file("reset", 0644, dentry,
  24928. + (void *)TIMERANDWAKEUP_LATENCY, &latency_hist_reset_fops);
  24929. + entry = debugfs_create_file("timerandwakeup", 0644,
  24930. + enable_root, (void *)&timerandwakeup_enabled_data,
  24931. + &enable_fops);
  24932. +#endif
  24933. + return 0;
  24934. +}
  24935. +
  24936. +device_initcall(latency_hist_init);
  24937. diff -Nur linux-4.4.13.orig/kernel/trace/Makefile linux-4.4.13/kernel/trace/Makefile
  24938. --- linux-4.4.13.orig/kernel/trace/Makefile 2016-06-08 03:14:51.000000000 +0200
  24939. +++ linux-4.4.13/kernel/trace/Makefile 2016-06-22 21:55:08.066523867 +0200
  24940. @@ -36,6 +36,10 @@
  24941. obj-$(CONFIG_IRQSOFF_TRACER) += trace_irqsoff.o
  24942. obj-$(CONFIG_PREEMPT_TRACER) += trace_irqsoff.o
  24943. obj-$(CONFIG_SCHED_TRACER) += trace_sched_wakeup.o
  24944. +obj-$(CONFIG_INTERRUPT_OFF_HIST) += latency_hist.o
  24945. +obj-$(CONFIG_PREEMPT_OFF_HIST) += latency_hist.o
  24946. +obj-$(CONFIG_WAKEUP_LATENCY_HIST) += latency_hist.o
  24947. +obj-$(CONFIG_MISSED_TIMER_OFFSETS_HIST) += latency_hist.o
  24948. obj-$(CONFIG_NOP_TRACER) += trace_nop.o
  24949. obj-$(CONFIG_STACK_TRACER) += trace_stack.o
  24950. obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o
  24951. diff -Nur linux-4.4.13.orig/kernel/trace/trace.c linux-4.4.13/kernel/trace/trace.c
  24952. --- linux-4.4.13.orig/kernel/trace/trace.c 2016-06-08 03:14:51.000000000 +0200
  24953. +++ linux-4.4.13/kernel/trace/trace.c 2016-06-22 21:55:08.066523867 +0200
  24954. @@ -1652,6 +1652,7 @@
  24955. struct task_struct *tsk = current;
  24956. entry->preempt_count = pc & 0xff;
  24957. + entry->preempt_lazy_count = preempt_lazy_count();
  24958. entry->pid = (tsk) ? tsk->pid : 0;
  24959. entry->flags =
  24960. #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
  24961. @@ -1661,8 +1662,11 @@
  24962. #endif
  24963. ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
  24964. ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
  24965. - (tif_need_resched() ? TRACE_FLAG_NEED_RESCHED : 0) |
  24966. + (tif_need_resched_now() ? TRACE_FLAG_NEED_RESCHED : 0) |
  24967. + (need_resched_lazy() ? TRACE_FLAG_NEED_RESCHED_LAZY : 0) |
  24968. (test_preempt_need_resched() ? TRACE_FLAG_PREEMPT_RESCHED : 0);
  24969. +
  24970. + entry->migrate_disable = (tsk) ? __migrate_disabled(tsk) & 0xFF : 0;
  24971. }
  24972. EXPORT_SYMBOL_GPL(tracing_generic_entry_update);
  24973. @@ -2555,14 +2559,17 @@
  24974. static void print_lat_help_header(struct seq_file *m)
  24975. {
  24976. - seq_puts(m, "# _------=> CPU# \n"
  24977. - "# / _-----=> irqs-off \n"
  24978. - "# | / _----=> need-resched \n"
  24979. - "# || / _---=> hardirq/softirq \n"
  24980. - "# ||| / _--=> preempt-depth \n"
  24981. - "# |||| / delay \n"
  24982. - "# cmd pid ||||| time | caller \n"
  24983. - "# \\ / ||||| \\ | / \n");
  24984. + seq_puts(m, "# _--------=> CPU# \n"
  24985. + "# / _-------=> irqs-off \n"
  24986. + "# | / _------=> need-resched \n"
  24987. + "# || / _-----=> need-resched_lazy \n"
  24988. + "# ||| / _----=> hardirq/softirq \n"
  24989. + "# |||| / _---=> preempt-depth \n"
  24990. + "# ||||| / _--=> preempt-lazy-depth\n"
  24991. + "# |||||| / _-=> migrate-disable \n"
  24992. + "# ||||||| / delay \n"
  24993. + "# cmd pid |||||||| time | caller \n"
  24994. + "# \\ / |||||||| \\ | / \n");
  24995. }
  24996. static void print_event_info(struct trace_buffer *buf, struct seq_file *m)
  24997. @@ -2588,11 +2595,14 @@
  24998. print_event_info(buf, m);
  24999. seq_puts(m, "# _-----=> irqs-off\n"
  25000. "# / _----=> need-resched\n"
  25001. - "# | / _---=> hardirq/softirq\n"
  25002. - "# || / _--=> preempt-depth\n"
  25003. - "# ||| / delay\n"
  25004. - "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n"
  25005. - "# | | | |||| | |\n");
  25006. + "# |/ _-----=> need-resched_lazy\n"
  25007. + "# || / _---=> hardirq/softirq\n"
  25008. + "# ||| / _--=> preempt-depth\n"
  25009. + "# |||| /_--=> preempt-lazy-depth\n"
  25010. + "# ||||| _-=> migrate-disable \n"
  25011. + "# ||||| / delay\n"
  25012. + "# TASK-PID CPU# |||||| TIMESTAMP FUNCTION\n"
  25013. + "# | | | |||||| | |\n");
  25014. }
  25015. void
  25016. diff -Nur linux-4.4.13.orig/kernel/trace/trace_events.c linux-4.4.13/kernel/trace/trace_events.c
  25017. --- linux-4.4.13.orig/kernel/trace/trace_events.c 2016-06-08 03:14:51.000000000 +0200
  25018. +++ linux-4.4.13/kernel/trace/trace_events.c 2016-06-22 21:55:08.070523867 +0200
  25019. @@ -188,6 +188,8 @@
  25020. __common_field(unsigned char, flags);
  25021. __common_field(unsigned char, preempt_count);
  25022. __common_field(int, pid);
  25023. + __common_field(unsigned short, migrate_disable);
  25024. + __common_field(unsigned short, padding);
  25025. return ret;
  25026. }
  25027. diff -Nur linux-4.4.13.orig/kernel/trace/trace.h linux-4.4.13/kernel/trace/trace.h
  25028. --- linux-4.4.13.orig/kernel/trace/trace.h 2016-06-08 03:14:51.000000000 +0200
  25029. +++ linux-4.4.13/kernel/trace/trace.h 2016-06-22 21:55:08.070523867 +0200
  25030. @@ -117,6 +117,7 @@
  25031. * NEED_RESCHED - reschedule is requested
  25032. * HARDIRQ - inside an interrupt handler
  25033. * SOFTIRQ - inside a softirq handler
  25034. + * NEED_RESCHED_LAZY - lazy reschedule is requested
  25035. */
  25036. enum trace_flag_type {
  25037. TRACE_FLAG_IRQS_OFF = 0x01,
  25038. @@ -125,6 +126,7 @@
  25039. TRACE_FLAG_HARDIRQ = 0x08,
  25040. TRACE_FLAG_SOFTIRQ = 0x10,
  25041. TRACE_FLAG_PREEMPT_RESCHED = 0x20,
  25042. + TRACE_FLAG_NEED_RESCHED_LAZY = 0x40,
  25043. };
  25044. #define TRACE_BUF_SIZE 1024
  25045. diff -Nur linux-4.4.13.orig/kernel/trace/trace_irqsoff.c linux-4.4.13/kernel/trace/trace_irqsoff.c
  25046. --- linux-4.4.13.orig/kernel/trace/trace_irqsoff.c 2016-06-08 03:14:51.000000000 +0200
  25047. +++ linux-4.4.13/kernel/trace/trace_irqsoff.c 2016-06-22 21:55:08.070523867 +0200
  25048. @@ -13,6 +13,7 @@
  25049. #include <linux/uaccess.h>
  25050. #include <linux/module.h>
  25051. #include <linux/ftrace.h>
  25052. +#include <trace/events/hist.h>
  25053. #include "trace.h"
  25054. @@ -424,11 +425,13 @@
  25055. {
  25056. if (preempt_trace() || irq_trace())
  25057. start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  25058. + trace_preemptirqsoff_hist_rcuidle(TRACE_START, 1);
  25059. }
  25060. EXPORT_SYMBOL_GPL(start_critical_timings);
  25061. void stop_critical_timings(void)
  25062. {
  25063. + trace_preemptirqsoff_hist_rcuidle(TRACE_STOP, 0);
  25064. if (preempt_trace() || irq_trace())
  25065. stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  25066. }
  25067. @@ -438,6 +441,7 @@
  25068. #ifdef CONFIG_PROVE_LOCKING
  25069. void time_hardirqs_on(unsigned long a0, unsigned long a1)
  25070. {
  25071. + trace_preemptirqsoff_hist_rcuidle(IRQS_ON, 0);
  25072. if (!preempt_trace() && irq_trace())
  25073. stop_critical_timing(a0, a1);
  25074. }
  25075. @@ -446,6 +450,7 @@
  25076. {
  25077. if (!preempt_trace() && irq_trace())
  25078. start_critical_timing(a0, a1);
  25079. + trace_preemptirqsoff_hist_rcuidle(IRQS_OFF, 1);
  25080. }
  25081. #else /* !CONFIG_PROVE_LOCKING */
  25082. @@ -471,6 +476,7 @@
  25083. */
  25084. void trace_hardirqs_on(void)
  25085. {
  25086. + trace_preemptirqsoff_hist(IRQS_ON, 0);
  25087. if (!preempt_trace() && irq_trace())
  25088. stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  25089. }
  25090. @@ -480,11 +486,13 @@
  25091. {
  25092. if (!preempt_trace() && irq_trace())
  25093. start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  25094. + trace_preemptirqsoff_hist(IRQS_OFF, 1);
  25095. }
  25096. EXPORT_SYMBOL(trace_hardirqs_off);
  25097. __visible void trace_hardirqs_on_caller(unsigned long caller_addr)
  25098. {
  25099. + trace_preemptirqsoff_hist(IRQS_ON, 0);
  25100. if (!preempt_trace() && irq_trace())
  25101. stop_critical_timing(CALLER_ADDR0, caller_addr);
  25102. }
  25103. @@ -494,6 +502,7 @@
  25104. {
  25105. if (!preempt_trace() && irq_trace())
  25106. start_critical_timing(CALLER_ADDR0, caller_addr);
  25107. + trace_preemptirqsoff_hist(IRQS_OFF, 1);
  25108. }
  25109. EXPORT_SYMBOL(trace_hardirqs_off_caller);
  25110. @@ -503,12 +512,14 @@
  25111. #ifdef CONFIG_PREEMPT_TRACER
  25112. void trace_preempt_on(unsigned long a0, unsigned long a1)
  25113. {
  25114. + trace_preemptirqsoff_hist(PREEMPT_ON, 0);
  25115. if (preempt_trace() && !irq_trace())
  25116. stop_critical_timing(a0, a1);
  25117. }
  25118. void trace_preempt_off(unsigned long a0, unsigned long a1)
  25119. {
  25120. + trace_preemptirqsoff_hist(PREEMPT_ON, 1);
  25121. if (preempt_trace() && !irq_trace())
  25122. start_critical_timing(a0, a1);
  25123. }
  25124. diff -Nur linux-4.4.13.orig/kernel/trace/trace_output.c linux-4.4.13/kernel/trace/trace_output.c
  25125. --- linux-4.4.13.orig/kernel/trace/trace_output.c 2016-06-08 03:14:51.000000000 +0200
  25126. +++ linux-4.4.13/kernel/trace/trace_output.c 2016-06-22 21:55:08.070523867 +0200
  25127. @@ -386,6 +386,7 @@
  25128. {
  25129. char hardsoft_irq;
  25130. char need_resched;
  25131. + char need_resched_lazy;
  25132. char irqs_off;
  25133. int hardirq;
  25134. int softirq;
  25135. @@ -413,6 +414,8 @@
  25136. need_resched = '.';
  25137. break;
  25138. }
  25139. + need_resched_lazy =
  25140. + (entry->flags & TRACE_FLAG_NEED_RESCHED_LAZY) ? 'L' : '.';
  25141. hardsoft_irq =
  25142. (hardirq && softirq) ? 'H' :
  25143. @@ -420,14 +423,25 @@
  25144. softirq ? 's' :
  25145. '.';
  25146. - trace_seq_printf(s, "%c%c%c",
  25147. - irqs_off, need_resched, hardsoft_irq);
  25148. + trace_seq_printf(s, "%c%c%c%c",
  25149. + irqs_off, need_resched, need_resched_lazy,
  25150. + hardsoft_irq);
  25151. if (entry->preempt_count)
  25152. trace_seq_printf(s, "%x", entry->preempt_count);
  25153. else
  25154. trace_seq_putc(s, '.');
  25155. + if (entry->preempt_lazy_count)
  25156. + trace_seq_printf(s, "%x", entry->preempt_lazy_count);
  25157. + else
  25158. + trace_seq_putc(s, '.');
  25159. +
  25160. + if (entry->migrate_disable)
  25161. + trace_seq_printf(s, "%x", entry->migrate_disable);
  25162. + else
  25163. + trace_seq_putc(s, '.');
  25164. +
  25165. return !trace_seq_has_overflowed(s);
  25166. }
  25167. diff -Nur linux-4.4.13.orig/kernel/user.c linux-4.4.13/kernel/user.c
  25168. --- linux-4.4.13.orig/kernel/user.c 2016-06-08 03:14:51.000000000 +0200
  25169. +++ linux-4.4.13/kernel/user.c 2016-06-22 21:55:08.070523867 +0200
  25170. @@ -161,11 +161,11 @@
  25171. if (!up)
  25172. return;
  25173. - local_irq_save(flags);
  25174. + local_irq_save_nort(flags);
  25175. if (atomic_dec_and_lock(&up->__count, &uidhash_lock))
  25176. free_user(up, flags);
  25177. else
  25178. - local_irq_restore(flags);
  25179. + local_irq_restore_nort(flags);
  25180. }
  25181. struct user_struct *alloc_uid(kuid_t uid)
  25182. diff -Nur linux-4.4.13.orig/kernel/watchdog.c linux-4.4.13/kernel/watchdog.c
  25183. --- linux-4.4.13.orig/kernel/watchdog.c 2016-06-08 03:14:51.000000000 +0200
  25184. +++ linux-4.4.13/kernel/watchdog.c 2016-06-22 21:55:08.070523867 +0200
  25185. @@ -299,6 +299,8 @@
  25186. #ifdef CONFIG_HARDLOCKUP_DETECTOR
  25187. +static DEFINE_RAW_SPINLOCK(watchdog_output_lock);
  25188. +
  25189. static struct perf_event_attr wd_hw_attr = {
  25190. .type = PERF_TYPE_HARDWARE,
  25191. .config = PERF_COUNT_HW_CPU_CYCLES,
  25192. @@ -333,6 +335,13 @@
  25193. /* only print hardlockups once */
  25194. if (__this_cpu_read(hard_watchdog_warn) == true)
  25195. return;
  25196. + /*
  25197. + * If early-printk is enabled then make sure we do not
  25198. + * lock up in printk() and kill console logging:
  25199. + */
  25200. + printk_kill();
  25201. +
  25202. + raw_spin_lock(&watchdog_output_lock);
  25203. pr_emerg("Watchdog detected hard LOCKUP on cpu %d", this_cpu);
  25204. print_modules();
  25205. @@ -350,8 +359,9 @@
  25206. !test_and_set_bit(0, &hardlockup_allcpu_dumped))
  25207. trigger_allbutself_cpu_backtrace();
  25208. + raw_spin_unlock(&watchdog_output_lock);
  25209. if (hardlockup_panic)
  25210. - panic("Hard LOCKUP");
  25211. + nmi_panic(regs, "Hard LOCKUP");
  25212. __this_cpu_write(hard_watchdog_warn, true);
  25213. return;
  25214. @@ -497,6 +507,7 @@
  25215. /* kick off the timer for the hardlockup detector */
  25216. hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  25217. hrtimer->function = watchdog_timer_fn;
  25218. + hrtimer->irqsafe = 1;
  25219. /* Enable the perf event */
  25220. watchdog_nmi_enable(cpu);
  25221. diff -Nur linux-4.4.13.orig/kernel/workqueue.c linux-4.4.13/kernel/workqueue.c
  25222. --- linux-4.4.13.orig/kernel/workqueue.c 2016-06-08 03:14:51.000000000 +0200
  25223. +++ linux-4.4.13/kernel/workqueue.c 2016-06-22 21:55:08.070523867 +0200
  25224. @@ -48,6 +48,8 @@
  25225. #include <linux/nodemask.h>
  25226. #include <linux/moduleparam.h>
  25227. #include <linux/uaccess.h>
  25228. +#include <linux/locallock.h>
  25229. +#include <linux/delay.h>
  25230. #include "workqueue_internal.h"
  25231. @@ -121,11 +123,16 @@
  25232. * cpu or grabbing pool->lock is enough for read access. If
  25233. * POOL_DISASSOCIATED is set, it's identical to L.
  25234. *
  25235. + * On RT we need the extra protection via rt_lock_idle_list() for
  25236. + * the list manipulations against read access from
  25237. + * wq_worker_sleeping(). All other places are nicely serialized via
  25238. + * pool->lock.
  25239. + *
  25240. * A: pool->attach_mutex protected.
  25241. *
  25242. * PL: wq_pool_mutex protected.
  25243. *
  25244. - * PR: wq_pool_mutex protected for writes. Sched-RCU protected for reads.
  25245. + * PR: wq_pool_mutex protected for writes. RCU protected for reads.
  25246. *
  25247. * PW: wq_pool_mutex and wq->mutex protected for writes. Either for reads.
  25248. *
  25249. @@ -134,7 +141,7 @@
  25250. *
  25251. * WQ: wq->mutex protected.
  25252. *
  25253. - * WR: wq->mutex protected for writes. Sched-RCU protected for reads.
  25254. + * WR: wq->mutex protected for writes. RCU protected for reads.
  25255. *
  25256. * MD: wq_mayday_lock protected.
  25257. */
  25258. @@ -183,7 +190,7 @@
  25259. atomic_t nr_running ____cacheline_aligned_in_smp;
  25260. /*
  25261. - * Destruction of pool is sched-RCU protected to allow dereferences
  25262. + * Destruction of pool is RCU protected to allow dereferences
  25263. * from get_work_pool().
  25264. */
  25265. struct rcu_head rcu;
  25266. @@ -212,7 +219,7 @@
  25267. /*
  25268. * Release of unbound pwq is punted to system_wq. See put_pwq()
  25269. * and pwq_unbound_release_workfn() for details. pool_workqueue
  25270. - * itself is also sched-RCU protected so that the first pwq can be
  25271. + * itself is also RCU protected so that the first pwq can be
  25272. * determined without grabbing wq->mutex.
  25273. */
  25274. struct work_struct unbound_release_work;
  25275. @@ -331,6 +338,8 @@
  25276. struct workqueue_struct *system_freezable_power_efficient_wq __read_mostly;
  25277. EXPORT_SYMBOL_GPL(system_freezable_power_efficient_wq);
  25278. +static DEFINE_LOCAL_IRQ_LOCK(pendingb_lock);
  25279. +
  25280. static int worker_thread(void *__worker);
  25281. static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
  25282. @@ -338,20 +347,20 @@
  25283. #include <trace/events/workqueue.h>
  25284. #define assert_rcu_or_pool_mutex() \
  25285. - RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held() && \
  25286. + RCU_LOCKDEP_WARN(!rcu_read_lock_held() && \
  25287. !lockdep_is_held(&wq_pool_mutex), \
  25288. - "sched RCU or wq_pool_mutex should be held")
  25289. + "RCU or wq_pool_mutex should be held")
  25290. #define assert_rcu_or_wq_mutex(wq) \
  25291. - RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held() && \
  25292. + RCU_LOCKDEP_WARN(!rcu_read_lock_held() && \
  25293. !lockdep_is_held(&wq->mutex), \
  25294. - "sched RCU or wq->mutex should be held")
  25295. + "RCU or wq->mutex should be held")
  25296. #define assert_rcu_or_wq_mutex_or_pool_mutex(wq) \
  25297. - RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held() && \
  25298. + RCU_LOCKDEP_WARN(!rcu_read_lock_held() && \
  25299. !lockdep_is_held(&wq->mutex) && \
  25300. !lockdep_is_held(&wq_pool_mutex), \
  25301. - "sched RCU, wq->mutex or wq_pool_mutex should be held")
  25302. + "RCU, wq->mutex or wq_pool_mutex should be held")
  25303. #define for_each_cpu_worker_pool(pool, cpu) \
  25304. for ((pool) = &per_cpu(cpu_worker_pools, cpu)[0]; \
  25305. @@ -363,7 +372,7 @@
  25306. * @pool: iteration cursor
  25307. * @pi: integer used for iteration
  25308. *
  25309. - * This must be called either with wq_pool_mutex held or sched RCU read
  25310. + * This must be called either with wq_pool_mutex held or RCU read
  25311. * locked. If the pool needs to be used beyond the locking in effect, the
  25312. * caller is responsible for guaranteeing that the pool stays online.
  25313. *
  25314. @@ -395,7 +404,7 @@
  25315. * @pwq: iteration cursor
  25316. * @wq: the target workqueue
  25317. *
  25318. - * This must be called either with wq->mutex held or sched RCU read locked.
  25319. + * This must be called either with wq->mutex held or RCU read locked.
  25320. * If the pwq needs to be used beyond the locking in effect, the caller is
  25321. * responsible for guaranteeing that the pwq stays online.
  25322. *
  25323. @@ -407,6 +416,31 @@
  25324. if (({ assert_rcu_or_wq_mutex(wq); false; })) { } \
  25325. else
  25326. +#ifdef CONFIG_PREEMPT_RT_BASE
  25327. +static inline void rt_lock_idle_list(struct worker_pool *pool)
  25328. +{
  25329. + preempt_disable();
  25330. +}
  25331. +static inline void rt_unlock_idle_list(struct worker_pool *pool)
  25332. +{
  25333. + preempt_enable();
  25334. +}
  25335. +static inline void sched_lock_idle_list(struct worker_pool *pool) { }
  25336. +static inline void sched_unlock_idle_list(struct worker_pool *pool) { }
  25337. +#else
  25338. +static inline void rt_lock_idle_list(struct worker_pool *pool) { }
  25339. +static inline void rt_unlock_idle_list(struct worker_pool *pool) { }
  25340. +static inline void sched_lock_idle_list(struct worker_pool *pool)
  25341. +{
  25342. + spin_lock_irq(&pool->lock);
  25343. +}
  25344. +static inline void sched_unlock_idle_list(struct worker_pool *pool)
  25345. +{
  25346. + spin_unlock_irq(&pool->lock);
  25347. +}
  25348. +#endif
  25349. +
  25350. +
  25351. #ifdef CONFIG_DEBUG_OBJECTS_WORK
  25352. static struct debug_obj_descr work_debug_descr;
  25353. @@ -557,7 +591,7 @@
  25354. * @wq: the target workqueue
  25355. * @node: the node ID
  25356. *
  25357. - * This must be called with any of wq_pool_mutex, wq->mutex or sched RCU
  25358. + * This must be called with any of wq_pool_mutex, wq->mutex or RCU
  25359. * read locked.
  25360. * If the pwq needs to be used beyond the locking in effect, the caller is
  25361. * responsible for guaranteeing that the pwq stays online.
  25362. @@ -701,8 +735,8 @@
  25363. * @work: the work item of interest
  25364. *
  25365. * Pools are created and destroyed under wq_pool_mutex, and allows read
  25366. - * access under sched-RCU read lock. As such, this function should be
  25367. - * called under wq_pool_mutex or with preemption disabled.
  25368. + * access under RCU read lock. As such, this function should be
  25369. + * called under wq_pool_mutex or inside of a rcu_read_lock() region.
  25370. *
  25371. * All fields of the returned pool are accessible as long as the above
  25372. * mentioned locking is in effect. If the returned pool needs to be used
  25373. @@ -839,51 +873,44 @@
  25374. */
  25375. static void wake_up_worker(struct worker_pool *pool)
  25376. {
  25377. - struct worker *worker = first_idle_worker(pool);
  25378. + struct worker *worker;
  25379. +
  25380. + rt_lock_idle_list(pool);
  25381. +
  25382. + worker = first_idle_worker(pool);
  25383. if (likely(worker))
  25384. wake_up_process(worker->task);
  25385. +
  25386. + rt_unlock_idle_list(pool);
  25387. }
  25388. /**
  25389. - * wq_worker_waking_up - a worker is waking up
  25390. - * @task: task waking up
  25391. - * @cpu: CPU @task is waking up to
  25392. + * wq_worker_running - a worker is running again
  25393. + * @task: task returning from sleep
  25394. *
  25395. - * This function is called during try_to_wake_up() when a worker is
  25396. - * being awoken.
  25397. - *
  25398. - * CONTEXT:
  25399. - * spin_lock_irq(rq->lock)
  25400. + * This function is called when a worker returns from schedule()
  25401. */
  25402. -void wq_worker_waking_up(struct task_struct *task, int cpu)
  25403. +void wq_worker_running(struct task_struct *task)
  25404. {
  25405. struct worker *worker = kthread_data(task);
  25406. - if (!(worker->flags & WORKER_NOT_RUNNING)) {
  25407. - WARN_ON_ONCE(worker->pool->cpu != cpu);
  25408. + if (!worker->sleeping)
  25409. + return;
  25410. + if (!(worker->flags & WORKER_NOT_RUNNING))
  25411. atomic_inc(&worker->pool->nr_running);
  25412. - }
  25413. + worker->sleeping = 0;
  25414. }
  25415. /**
  25416. * wq_worker_sleeping - a worker is going to sleep
  25417. * @task: task going to sleep
  25418. - * @cpu: CPU in question, must be the current CPU number
  25419. - *
  25420. - * This function is called during schedule() when a busy worker is
  25421. - * going to sleep. Worker on the same cpu can be woken up by
  25422. - * returning pointer to its task.
  25423. - *
  25424. - * CONTEXT:
  25425. - * spin_lock_irq(rq->lock)
  25426. - *
  25427. - * Return:
  25428. - * Worker task on @cpu to wake up, %NULL if none.
  25429. + * This function is called from schedule() when a busy worker is
  25430. + * going to sleep.
  25431. */
  25432. -struct task_struct *wq_worker_sleeping(struct task_struct *task, int cpu)
  25433. +void wq_worker_sleeping(struct task_struct *task)
  25434. {
  25435. - struct worker *worker = kthread_data(task), *to_wakeup = NULL;
  25436. + struct worker *worker = kthread_data(task);
  25437. struct worker_pool *pool;
  25438. /*
  25439. @@ -892,29 +919,26 @@
  25440. * checking NOT_RUNNING.
  25441. */
  25442. if (worker->flags & WORKER_NOT_RUNNING)
  25443. - return NULL;
  25444. + return;
  25445. pool = worker->pool;
  25446. - /* this can only happen on the local cpu */
  25447. - if (WARN_ON_ONCE(cpu != raw_smp_processor_id() || pool->cpu != cpu))
  25448. - return NULL;
  25449. + if (WARN_ON_ONCE(worker->sleeping))
  25450. + return;
  25451. +
  25452. + worker->sleeping = 1;
  25453. /*
  25454. * The counterpart of the following dec_and_test, implied mb,
  25455. * worklist not empty test sequence is in insert_work().
  25456. * Please read comment there.
  25457. - *
  25458. - * NOT_RUNNING is clear. This means that we're bound to and
  25459. - * running on the local cpu w/ rq lock held and preemption
  25460. - * disabled, which in turn means that none else could be
  25461. - * manipulating idle_list, so dereferencing idle_list without pool
  25462. - * lock is safe.
  25463. */
  25464. if (atomic_dec_and_test(&pool->nr_running) &&
  25465. - !list_empty(&pool->worklist))
  25466. - to_wakeup = first_idle_worker(pool);
  25467. - return to_wakeup ? to_wakeup->task : NULL;
  25468. + !list_empty(&pool->worklist)) {
  25469. + sched_lock_idle_list(pool);
  25470. + wake_up_worker(pool);
  25471. + sched_unlock_idle_list(pool);
  25472. + }
  25473. }
  25474. /**
  25475. @@ -1108,12 +1132,12 @@
  25476. {
  25477. if (pwq) {
  25478. /*
  25479. - * As both pwqs and pools are sched-RCU protected, the
  25480. + * As both pwqs and pools are RCU protected, the
  25481. * following lock operations are safe.
  25482. */
  25483. - spin_lock_irq(&pwq->pool->lock);
  25484. + local_spin_lock_irq(pendingb_lock, &pwq->pool->lock);
  25485. put_pwq(pwq);
  25486. - spin_unlock_irq(&pwq->pool->lock);
  25487. + local_spin_unlock_irq(pendingb_lock, &pwq->pool->lock);
  25488. }
  25489. }
  25490. @@ -1215,7 +1239,7 @@
  25491. struct worker_pool *pool;
  25492. struct pool_workqueue *pwq;
  25493. - local_irq_save(*flags);
  25494. + local_lock_irqsave(pendingb_lock, *flags);
  25495. /* try to steal the timer if it exists */
  25496. if (is_dwork) {
  25497. @@ -1234,6 +1258,7 @@
  25498. if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)))
  25499. return 0;
  25500. + rcu_read_lock();
  25501. /*
  25502. * The queueing is in progress, or it is already queued. Try to
  25503. * steal it from ->worklist without clearing WORK_STRUCT_PENDING.
  25504. @@ -1272,14 +1297,16 @@
  25505. set_work_pool_and_keep_pending(work, pool->id);
  25506. spin_unlock(&pool->lock);
  25507. + rcu_read_unlock();
  25508. return 1;
  25509. }
  25510. spin_unlock(&pool->lock);
  25511. fail:
  25512. - local_irq_restore(*flags);
  25513. + rcu_read_unlock();
  25514. + local_unlock_irqrestore(pendingb_lock, *flags);
  25515. if (work_is_canceling(work))
  25516. return -ENOENT;
  25517. - cpu_relax();
  25518. + cpu_chill();
  25519. return -EAGAIN;
  25520. }
  25521. @@ -1348,7 +1375,7 @@
  25522. * queued or lose PENDING. Grabbing PENDING and queueing should
  25523. * happen with IRQ disabled.
  25524. */
  25525. - WARN_ON_ONCE(!irqs_disabled());
  25526. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  25527. debug_work_activate(work);
  25528. @@ -1356,6 +1383,8 @@
  25529. if (unlikely(wq->flags & __WQ_DRAINING) &&
  25530. WARN_ON_ONCE(!is_chained_work(wq)))
  25531. return;
  25532. +
  25533. + rcu_read_lock();
  25534. retry:
  25535. if (req_cpu == WORK_CPU_UNBOUND)
  25536. cpu = raw_smp_processor_id();
  25537. @@ -1412,10 +1441,8 @@
  25538. /* pwq determined, queue */
  25539. trace_workqueue_queue_work(req_cpu, pwq, work);
  25540. - if (WARN_ON(!list_empty(&work->entry))) {
  25541. - spin_unlock(&pwq->pool->lock);
  25542. - return;
  25543. - }
  25544. + if (WARN_ON(!list_empty(&work->entry)))
  25545. + goto out;
  25546. pwq->nr_in_flight[pwq->work_color]++;
  25547. work_flags = work_color_to_flags(pwq->work_color);
  25548. @@ -1431,7 +1458,9 @@
  25549. insert_work(pwq, work, worklist, work_flags);
  25550. +out:
  25551. spin_unlock(&pwq->pool->lock);
  25552. + rcu_read_unlock();
  25553. }
  25554. /**
  25555. @@ -1451,14 +1480,14 @@
  25556. bool ret = false;
  25557. unsigned long flags;
  25558. - local_irq_save(flags);
  25559. + local_lock_irqsave(pendingb_lock,flags);
  25560. if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
  25561. __queue_work(cpu, wq, work);
  25562. ret = true;
  25563. }
  25564. - local_irq_restore(flags);
  25565. + local_unlock_irqrestore(pendingb_lock, flags);
  25566. return ret;
  25567. }
  25568. EXPORT_SYMBOL(queue_work_on);
  25569. @@ -1525,14 +1554,14 @@
  25570. unsigned long flags;
  25571. /* read the comment in __queue_work() */
  25572. - local_irq_save(flags);
  25573. + local_lock_irqsave(pendingb_lock, flags);
  25574. if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
  25575. __queue_delayed_work(cpu, wq, dwork, delay);
  25576. ret = true;
  25577. }
  25578. - local_irq_restore(flags);
  25579. + local_unlock_irqrestore(pendingb_lock, flags);
  25580. return ret;
  25581. }
  25582. EXPORT_SYMBOL(queue_delayed_work_on);
  25583. @@ -1567,7 +1596,7 @@
  25584. if (likely(ret >= 0)) {
  25585. __queue_delayed_work(cpu, wq, dwork, delay);
  25586. - local_irq_restore(flags);
  25587. + local_unlock_irqrestore(pendingb_lock, flags);
  25588. }
  25589. /* -ENOENT from try_to_grab_pending() becomes %true */
  25590. @@ -1600,7 +1629,9 @@
  25591. worker->last_active = jiffies;
  25592. /* idle_list is LIFO */
  25593. + rt_lock_idle_list(pool);
  25594. list_add(&worker->entry, &pool->idle_list);
  25595. + rt_unlock_idle_list(pool);
  25596. if (too_many_workers(pool) && !timer_pending(&pool->idle_timer))
  25597. mod_timer(&pool->idle_timer, jiffies + IDLE_WORKER_TIMEOUT);
  25598. @@ -1633,7 +1664,9 @@
  25599. return;
  25600. worker_clr_flags(worker, WORKER_IDLE);
  25601. pool->nr_idle--;
  25602. + rt_lock_idle_list(pool);
  25603. list_del_init(&worker->entry);
  25604. + rt_unlock_idle_list(pool);
  25605. }
  25606. static struct worker *alloc_worker(int node)
  25607. @@ -1799,7 +1832,9 @@
  25608. pool->nr_workers--;
  25609. pool->nr_idle--;
  25610. + rt_lock_idle_list(pool);
  25611. list_del_init(&worker->entry);
  25612. + rt_unlock_idle_list(pool);
  25613. worker->flags |= WORKER_DIE;
  25614. wake_up_process(worker->task);
  25615. }
  25616. @@ -2716,14 +2751,14 @@
  25617. might_sleep();
  25618. - local_irq_disable();
  25619. + rcu_read_lock();
  25620. pool = get_work_pool(work);
  25621. if (!pool) {
  25622. - local_irq_enable();
  25623. + rcu_read_unlock();
  25624. return false;
  25625. }
  25626. - spin_lock(&pool->lock);
  25627. + spin_lock_irq(&pool->lock);
  25628. /* see the comment in try_to_grab_pending() with the same code */
  25629. pwq = get_work_pwq(work);
  25630. if (pwq) {
  25631. @@ -2750,10 +2785,11 @@
  25632. else
  25633. lock_map_acquire_read(&pwq->wq->lockdep_map);
  25634. lock_map_release(&pwq->wq->lockdep_map);
  25635. -
  25636. + rcu_read_unlock();
  25637. return true;
  25638. already_gone:
  25639. spin_unlock_irq(&pool->lock);
  25640. + rcu_read_unlock();
  25641. return false;
  25642. }
  25643. @@ -2840,7 +2876,7 @@
  25644. /* tell other tasks trying to grab @work to back off */
  25645. mark_work_canceling(work);
  25646. - local_irq_restore(flags);
  25647. + local_unlock_irqrestore(pendingb_lock, flags);
  25648. flush_work(work);
  25649. clear_work_data(work);
  25650. @@ -2895,10 +2931,10 @@
  25651. */
  25652. bool flush_delayed_work(struct delayed_work *dwork)
  25653. {
  25654. - local_irq_disable();
  25655. + local_lock_irq(pendingb_lock);
  25656. if (del_timer_sync(&dwork->timer))
  25657. __queue_work(dwork->cpu, dwork->wq, &dwork->work);
  25658. - local_irq_enable();
  25659. + local_unlock_irq(pendingb_lock);
  25660. return flush_work(&dwork->work);
  25661. }
  25662. EXPORT_SYMBOL(flush_delayed_work);
  25663. @@ -2933,7 +2969,7 @@
  25664. set_work_pool_and_clear_pending(&dwork->work,
  25665. get_work_pool_id(&dwork->work));
  25666. - local_irq_restore(flags);
  25667. + local_unlock_irqrestore(pendingb_lock, flags);
  25668. return ret;
  25669. }
  25670. EXPORT_SYMBOL(cancel_delayed_work);
  25671. @@ -3161,7 +3197,7 @@
  25672. * put_unbound_pool - put a worker_pool
  25673. * @pool: worker_pool to put
  25674. *
  25675. - * Put @pool. If its refcnt reaches zero, it gets destroyed in sched-RCU
  25676. + * Put @pool. If its refcnt reaches zero, it gets destroyed in RCU
  25677. * safe manner. get_unbound_pool() calls this function on its failure path
  25678. * and this function should be able to release pools which went through,
  25679. * successfully or not, init_worker_pool().
  25680. @@ -3215,8 +3251,8 @@
  25681. del_timer_sync(&pool->idle_timer);
  25682. del_timer_sync(&pool->mayday_timer);
  25683. - /* sched-RCU protected to allow dereferences from get_work_pool() */
  25684. - call_rcu_sched(&pool->rcu, rcu_free_pool);
  25685. + /* RCU protected to allow dereferences from get_work_pool() */
  25686. + call_rcu(&pool->rcu, rcu_free_pool);
  25687. }
  25688. /**
  25689. @@ -3323,14 +3359,14 @@
  25690. put_unbound_pool(pool);
  25691. mutex_unlock(&wq_pool_mutex);
  25692. - call_rcu_sched(&pwq->rcu, rcu_free_pwq);
  25693. + call_rcu(&pwq->rcu, rcu_free_pwq);
  25694. /*
  25695. * If we're the last pwq going away, @wq is already dead and no one
  25696. * is gonna access it anymore. Schedule RCU free.
  25697. */
  25698. if (is_last)
  25699. - call_rcu_sched(&wq->rcu, rcu_free_wq);
  25700. + call_rcu(&wq->rcu, rcu_free_wq);
  25701. }
  25702. /**
  25703. @@ -3983,7 +4019,7 @@
  25704. * The base ref is never dropped on per-cpu pwqs. Directly
  25705. * schedule RCU free.
  25706. */
  25707. - call_rcu_sched(&wq->rcu, rcu_free_wq);
  25708. + call_rcu(&wq->rcu, rcu_free_wq);
  25709. } else {
  25710. /*
  25711. * We're the sole accessor of @wq at this point. Directly
  25712. @@ -4076,7 +4112,8 @@
  25713. struct pool_workqueue *pwq;
  25714. bool ret;
  25715. - rcu_read_lock_sched();
  25716. + rcu_read_lock();
  25717. + preempt_disable();
  25718. if (cpu == WORK_CPU_UNBOUND)
  25719. cpu = smp_processor_id();
  25720. @@ -4087,7 +4124,8 @@
  25721. pwq = unbound_pwq_by_node(wq, cpu_to_node(cpu));
  25722. ret = !list_empty(&pwq->delayed_works);
  25723. - rcu_read_unlock_sched();
  25724. + preempt_enable();
  25725. + rcu_read_unlock();
  25726. return ret;
  25727. }
  25728. @@ -4113,15 +4151,15 @@
  25729. if (work_pending(work))
  25730. ret |= WORK_BUSY_PENDING;
  25731. - local_irq_save(flags);
  25732. + rcu_read_lock();
  25733. pool = get_work_pool(work);
  25734. if (pool) {
  25735. - spin_lock(&pool->lock);
  25736. + spin_lock_irqsave(&pool->lock, flags);
  25737. if (find_worker_executing_work(pool, work))
  25738. ret |= WORK_BUSY_RUNNING;
  25739. - spin_unlock(&pool->lock);
  25740. + spin_unlock_irqrestore(&pool->lock, flags);
  25741. }
  25742. - local_irq_restore(flags);
  25743. + rcu_read_unlock();
  25744. return ret;
  25745. }
  25746. @@ -4310,7 +4348,7 @@
  25747. unsigned long flags;
  25748. int pi;
  25749. - rcu_read_lock_sched();
  25750. + rcu_read_lock();
  25751. pr_info("Showing busy workqueues and worker pools:\n");
  25752. @@ -4361,7 +4399,7 @@
  25753. spin_unlock_irqrestore(&pool->lock, flags);
  25754. }
  25755. - rcu_read_unlock_sched();
  25756. + rcu_read_unlock();
  25757. }
  25758. /*
  25759. @@ -4722,16 +4760,16 @@
  25760. * nr_active is monotonically decreasing. It's safe
  25761. * to peek without lock.
  25762. */
  25763. - rcu_read_lock_sched();
  25764. + rcu_read_lock();
  25765. for_each_pwq(pwq, wq) {
  25766. WARN_ON_ONCE(pwq->nr_active < 0);
  25767. if (pwq->nr_active) {
  25768. busy = true;
  25769. - rcu_read_unlock_sched();
  25770. + rcu_read_unlock();
  25771. goto out_unlock;
  25772. }
  25773. }
  25774. - rcu_read_unlock_sched();
  25775. + rcu_read_unlock();
  25776. }
  25777. out_unlock:
  25778. mutex_unlock(&wq_pool_mutex);
  25779. @@ -4921,7 +4959,8 @@
  25780. const char *delim = "";
  25781. int node, written = 0;
  25782. - rcu_read_lock_sched();
  25783. + get_online_cpus();
  25784. + rcu_read_lock();
  25785. for_each_node(node) {
  25786. written += scnprintf(buf + written, PAGE_SIZE - written,
  25787. "%s%d:%d", delim, node,
  25788. @@ -4929,7 +4968,8 @@
  25789. delim = " ";
  25790. }
  25791. written += scnprintf(buf + written, PAGE_SIZE - written, "\n");
  25792. - rcu_read_unlock_sched();
  25793. + rcu_read_unlock();
  25794. + put_online_cpus();
  25795. return written;
  25796. }
  25797. diff -Nur linux-4.4.13.orig/kernel/workqueue_internal.h linux-4.4.13/kernel/workqueue_internal.h
  25798. --- linux-4.4.13.orig/kernel/workqueue_internal.h 2016-06-08 03:14:51.000000000 +0200
  25799. +++ linux-4.4.13/kernel/workqueue_internal.h 2016-06-22 21:55:08.070523867 +0200
  25800. @@ -43,6 +43,7 @@
  25801. unsigned long last_active; /* L: last active timestamp */
  25802. unsigned int flags; /* X: flags */
  25803. int id; /* I: worker id */
  25804. + int sleeping; /* None */
  25805. /*
  25806. * Opaque string set with work_set_desc(). Printed out with task
  25807. @@ -68,7 +69,7 @@
  25808. * Scheduler hooks for concurrency managed workqueue. Only to be used from
  25809. * sched/core.c and workqueue.c.
  25810. */
  25811. -void wq_worker_waking_up(struct task_struct *task, int cpu);
  25812. -struct task_struct *wq_worker_sleeping(struct task_struct *task, int cpu);
  25813. +void wq_worker_running(struct task_struct *task);
  25814. +void wq_worker_sleeping(struct task_struct *task);
  25815. #endif /* _KERNEL_WORKQUEUE_INTERNAL_H */
  25816. diff -Nur linux-4.4.13.orig/lib/debugobjects.c linux-4.4.13/lib/debugobjects.c
  25817. --- linux-4.4.13.orig/lib/debugobjects.c 2016-06-08 03:14:51.000000000 +0200
  25818. +++ linux-4.4.13/lib/debugobjects.c 2016-06-22 21:55:08.070523867 +0200
  25819. @@ -309,7 +309,10 @@
  25820. struct debug_obj *obj;
  25821. unsigned long flags;
  25822. - fill_pool();
  25823. +#ifdef CONFIG_PREEMPT_RT_FULL
  25824. + if (preempt_count() == 0 && !irqs_disabled())
  25825. +#endif
  25826. + fill_pool();
  25827. db = get_bucket((unsigned long) addr);
  25828. diff -Nur linux-4.4.13.orig/lib/idr.c linux-4.4.13/lib/idr.c
  25829. --- linux-4.4.13.orig/lib/idr.c 2016-06-08 03:14:51.000000000 +0200
  25830. +++ linux-4.4.13/lib/idr.c 2016-06-22 21:55:08.070523867 +0200
  25831. @@ -30,6 +30,7 @@
  25832. #include <linux/idr.h>
  25833. #include <linux/spinlock.h>
  25834. #include <linux/percpu.h>
  25835. +#include <linux/locallock.h>
  25836. #define MAX_IDR_SHIFT (sizeof(int) * 8 - 1)
  25837. #define MAX_IDR_BIT (1U << MAX_IDR_SHIFT)
  25838. @@ -45,6 +46,37 @@
  25839. static DEFINE_PER_CPU(int, idr_preload_cnt);
  25840. static DEFINE_SPINLOCK(simple_ida_lock);
  25841. +#ifdef CONFIG_PREEMPT_RT_FULL
  25842. +static DEFINE_LOCAL_IRQ_LOCK(idr_lock);
  25843. +
  25844. +static inline void idr_preload_lock(void)
  25845. +{
  25846. + local_lock(idr_lock);
  25847. +}
  25848. +
  25849. +static inline void idr_preload_unlock(void)
  25850. +{
  25851. + local_unlock(idr_lock);
  25852. +}
  25853. +
  25854. +void idr_preload_end(void)
  25855. +{
  25856. + idr_preload_unlock();
  25857. +}
  25858. +EXPORT_SYMBOL(idr_preload_end);
  25859. +#else
  25860. +static inline void idr_preload_lock(void)
  25861. +{
  25862. + preempt_disable();
  25863. +}
  25864. +
  25865. +static inline void idr_preload_unlock(void)
  25866. +{
  25867. + preempt_enable();
  25868. +}
  25869. +#endif
  25870. +
  25871. +
  25872. /* the maximum ID which can be allocated given idr->layers */
  25873. static int idr_max(int layers)
  25874. {
  25875. @@ -115,14 +147,14 @@
  25876. * context. See idr_preload() for details.
  25877. */
  25878. if (!in_interrupt()) {
  25879. - preempt_disable();
  25880. + idr_preload_lock();
  25881. new = __this_cpu_read(idr_preload_head);
  25882. if (new) {
  25883. __this_cpu_write(idr_preload_head, new->ary[0]);
  25884. __this_cpu_dec(idr_preload_cnt);
  25885. new->ary[0] = NULL;
  25886. }
  25887. - preempt_enable();
  25888. + idr_preload_unlock();
  25889. if (new)
  25890. return new;
  25891. }
  25892. @@ -366,7 +398,6 @@
  25893. idr_mark_full(pa, id);
  25894. }
  25895. -
  25896. /**
  25897. * idr_preload - preload for idr_alloc()
  25898. * @gfp_mask: allocation mask to use for preloading
  25899. @@ -401,7 +432,7 @@
  25900. WARN_ON_ONCE(in_interrupt());
  25901. might_sleep_if(gfpflags_allow_blocking(gfp_mask));
  25902. - preempt_disable();
  25903. + idr_preload_lock();
  25904. /*
  25905. * idr_alloc() is likely to succeed w/o full idr_layer buffer and
  25906. @@ -413,9 +444,9 @@
  25907. while (__this_cpu_read(idr_preload_cnt) < MAX_IDR_FREE) {
  25908. struct idr_layer *new;
  25909. - preempt_enable();
  25910. + idr_preload_unlock();
  25911. new = kmem_cache_zalloc(idr_layer_cache, gfp_mask);
  25912. - preempt_disable();
  25913. + idr_preload_lock();
  25914. if (!new)
  25915. break;
  25916. diff -Nur linux-4.4.13.orig/lib/Kconfig linux-4.4.13/lib/Kconfig
  25917. --- linux-4.4.13.orig/lib/Kconfig 2016-06-08 03:14:51.000000000 +0200
  25918. +++ linux-4.4.13/lib/Kconfig 2016-06-22 21:55:08.070523867 +0200
  25919. @@ -397,6 +397,7 @@
  25920. config CPUMASK_OFFSTACK
  25921. bool "Force CPU masks off stack" if DEBUG_PER_CPU_MAPS
  25922. + depends on !PREEMPT_RT_FULL
  25923. help
  25924. Use dynamic allocation for cpumask_var_t, instead of putting
  25925. them on the stack. This is a bit more expensive, but avoids
  25926. diff -Nur linux-4.4.13.orig/lib/locking-selftest.c linux-4.4.13/lib/locking-selftest.c
  25927. --- linux-4.4.13.orig/lib/locking-selftest.c 2016-06-08 03:14:51.000000000 +0200
  25928. +++ linux-4.4.13/lib/locking-selftest.c 2016-06-22 21:55:08.070523867 +0200
  25929. @@ -590,6 +590,8 @@
  25930. #include "locking-selftest-spin-hardirq.h"
  25931. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_spin)
  25932. +#ifndef CONFIG_PREEMPT_RT_FULL
  25933. +
  25934. #include "locking-selftest-rlock-hardirq.h"
  25935. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_rlock)
  25936. @@ -605,9 +607,12 @@
  25937. #include "locking-selftest-wlock-softirq.h"
  25938. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_wlock)
  25939. +#endif
  25940. +
  25941. #undef E1
  25942. #undef E2
  25943. +#ifndef CONFIG_PREEMPT_RT_FULL
  25944. /*
  25945. * Enabling hardirqs with a softirq-safe lock held:
  25946. */
  25947. @@ -640,6 +645,8 @@
  25948. #undef E1
  25949. #undef E2
  25950. +#endif
  25951. +
  25952. /*
  25953. * Enabling irqs with an irq-safe lock held:
  25954. */
  25955. @@ -663,6 +670,8 @@
  25956. #include "locking-selftest-spin-hardirq.h"
  25957. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_spin)
  25958. +#ifndef CONFIG_PREEMPT_RT_FULL
  25959. +
  25960. #include "locking-selftest-rlock-hardirq.h"
  25961. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_rlock)
  25962. @@ -678,6 +687,8 @@
  25963. #include "locking-selftest-wlock-softirq.h"
  25964. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_wlock)
  25965. +#endif
  25966. +
  25967. #undef E1
  25968. #undef E2
  25969. @@ -709,6 +720,8 @@
  25970. #include "locking-selftest-spin-hardirq.h"
  25971. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_spin)
  25972. +#ifndef CONFIG_PREEMPT_RT_FULL
  25973. +
  25974. #include "locking-selftest-rlock-hardirq.h"
  25975. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_rlock)
  25976. @@ -724,6 +737,8 @@
  25977. #include "locking-selftest-wlock-softirq.h"
  25978. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_wlock)
  25979. +#endif
  25980. +
  25981. #undef E1
  25982. #undef E2
  25983. #undef E3
  25984. @@ -757,6 +772,8 @@
  25985. #include "locking-selftest-spin-hardirq.h"
  25986. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_spin)
  25987. +#ifndef CONFIG_PREEMPT_RT_FULL
  25988. +
  25989. #include "locking-selftest-rlock-hardirq.h"
  25990. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_rlock)
  25991. @@ -772,10 +789,14 @@
  25992. #include "locking-selftest-wlock-softirq.h"
  25993. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_wlock)
  25994. +#endif
  25995. +
  25996. #undef E1
  25997. #undef E2
  25998. #undef E3
  25999. +#ifndef CONFIG_PREEMPT_RT_FULL
  26000. +
  26001. /*
  26002. * read-lock / write-lock irq inversion.
  26003. *
  26004. @@ -838,6 +859,10 @@
  26005. #undef E2
  26006. #undef E3
  26007. +#endif
  26008. +
  26009. +#ifndef CONFIG_PREEMPT_RT_FULL
  26010. +
  26011. /*
  26012. * read-lock / write-lock recursion that is actually safe.
  26013. */
  26014. @@ -876,6 +901,8 @@
  26015. #undef E2
  26016. #undef E3
  26017. +#endif
  26018. +
  26019. /*
  26020. * read-lock / write-lock recursion that is unsafe.
  26021. */
  26022. @@ -1858,6 +1885,7 @@
  26023. printk(" --------------------------------------------------------------------------\n");
  26024. +#ifndef CONFIG_PREEMPT_RT_FULL
  26025. /*
  26026. * irq-context testcases:
  26027. */
  26028. @@ -1870,6 +1898,28 @@
  26029. DO_TESTCASE_6x2("irq read-recursion", irq_read_recursion);
  26030. // DO_TESTCASE_6x2B("irq read-recursion #2", irq_read_recursion2);
  26031. +#else
  26032. + /* On -rt, we only do hardirq context test for raw spinlock */
  26033. + DO_TESTCASE_1B("hard-irqs-on + irq-safe-A", irqsafe1_hard_spin, 12);
  26034. + DO_TESTCASE_1B("hard-irqs-on + irq-safe-A", irqsafe1_hard_spin, 21);
  26035. +
  26036. + DO_TESTCASE_1B("hard-safe-A + irqs-on", irqsafe2B_hard_spin, 12);
  26037. + DO_TESTCASE_1B("hard-safe-A + irqs-on", irqsafe2B_hard_spin, 21);
  26038. +
  26039. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 123);
  26040. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 132);
  26041. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 213);
  26042. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 231);
  26043. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 312);
  26044. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 321);
  26045. +
  26046. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 123);
  26047. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 132);
  26048. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 213);
  26049. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 231);
  26050. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 312);
  26051. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 321);
  26052. +#endif
  26053. ww_tests();
  26054. diff -Nur linux-4.4.13.orig/lib/percpu_ida.c linux-4.4.13/lib/percpu_ida.c
  26055. --- linux-4.4.13.orig/lib/percpu_ida.c 2016-06-08 03:14:51.000000000 +0200
  26056. +++ linux-4.4.13/lib/percpu_ida.c 2016-06-22 21:55:08.074523867 +0200
  26057. @@ -26,6 +26,9 @@
  26058. #include <linux/string.h>
  26059. #include <linux/spinlock.h>
  26060. #include <linux/percpu_ida.h>
  26061. +#include <linux/locallock.h>
  26062. +
  26063. +static DEFINE_LOCAL_IRQ_LOCK(irq_off_lock);
  26064. struct percpu_ida_cpu {
  26065. /*
  26066. @@ -148,13 +151,13 @@
  26067. unsigned long flags;
  26068. int tag;
  26069. - local_irq_save(flags);
  26070. + local_lock_irqsave(irq_off_lock, flags);
  26071. tags = this_cpu_ptr(pool->tag_cpu);
  26072. /* Fastpath */
  26073. tag = alloc_local_tag(tags);
  26074. if (likely(tag >= 0)) {
  26075. - local_irq_restore(flags);
  26076. + local_unlock_irqrestore(irq_off_lock, flags);
  26077. return tag;
  26078. }
  26079. @@ -173,6 +176,7 @@
  26080. if (!tags->nr_free)
  26081. alloc_global_tags(pool, tags);
  26082. +
  26083. if (!tags->nr_free)
  26084. steal_tags(pool, tags);
  26085. @@ -184,7 +188,7 @@
  26086. }
  26087. spin_unlock(&pool->lock);
  26088. - local_irq_restore(flags);
  26089. + local_unlock_irqrestore(irq_off_lock, flags);
  26090. if (tag >= 0 || state == TASK_RUNNING)
  26091. break;
  26092. @@ -196,7 +200,7 @@
  26093. schedule();
  26094. - local_irq_save(flags);
  26095. + local_lock_irqsave(irq_off_lock, flags);
  26096. tags = this_cpu_ptr(pool->tag_cpu);
  26097. }
  26098. if (state != TASK_RUNNING)
  26099. @@ -221,7 +225,7 @@
  26100. BUG_ON(tag >= pool->nr_tags);
  26101. - local_irq_save(flags);
  26102. + local_lock_irqsave(irq_off_lock, flags);
  26103. tags = this_cpu_ptr(pool->tag_cpu);
  26104. spin_lock(&tags->lock);
  26105. @@ -253,7 +257,7 @@
  26106. spin_unlock(&pool->lock);
  26107. }
  26108. - local_irq_restore(flags);
  26109. + local_unlock_irqrestore(irq_off_lock, flags);
  26110. }
  26111. EXPORT_SYMBOL_GPL(percpu_ida_free);
  26112. @@ -345,7 +349,7 @@
  26113. struct percpu_ida_cpu *remote;
  26114. unsigned cpu, i, err = 0;
  26115. - local_irq_save(flags);
  26116. + local_lock_irqsave(irq_off_lock, flags);
  26117. for_each_possible_cpu(cpu) {
  26118. remote = per_cpu_ptr(pool->tag_cpu, cpu);
  26119. spin_lock(&remote->lock);
  26120. @@ -367,7 +371,7 @@
  26121. }
  26122. spin_unlock(&pool->lock);
  26123. out:
  26124. - local_irq_restore(flags);
  26125. + local_unlock_irqrestore(irq_off_lock, flags);
  26126. return err;
  26127. }
  26128. EXPORT_SYMBOL_GPL(percpu_ida_for_each_free);
  26129. diff -Nur linux-4.4.13.orig/lib/radix-tree.c linux-4.4.13/lib/radix-tree.c
  26130. --- linux-4.4.13.orig/lib/radix-tree.c 2016-06-08 03:14:51.000000000 +0200
  26131. +++ linux-4.4.13/lib/radix-tree.c 2016-06-22 21:55:08.074523867 +0200
  26132. @@ -196,13 +196,14 @@
  26133. * succeed in getting a node here (and never reach
  26134. * kmem_cache_alloc)
  26135. */
  26136. - rtp = this_cpu_ptr(&radix_tree_preloads);
  26137. + rtp = &get_cpu_var(radix_tree_preloads);
  26138. if (rtp->nr) {
  26139. ret = rtp->nodes;
  26140. rtp->nodes = ret->private_data;
  26141. ret->private_data = NULL;
  26142. rtp->nr--;
  26143. }
  26144. + put_cpu_var(radix_tree_preloads);
  26145. /*
  26146. * Update the allocation stack trace as this is more useful
  26147. * for debugging.
  26148. @@ -242,6 +243,7 @@
  26149. call_rcu(&node->rcu_head, radix_tree_node_rcu_free);
  26150. }
  26151. +#ifndef CONFIG_PREEMPT_RT_FULL
  26152. /*
  26153. * Load up this CPU's radix_tree_node buffer with sufficient objects to
  26154. * ensure that the addition of a single element in the tree cannot fail. On
  26155. @@ -310,6 +312,7 @@
  26156. return 0;
  26157. }
  26158. EXPORT_SYMBOL(radix_tree_maybe_preload);
  26159. +#endif
  26160. /*
  26161. * Return the maximum key which can be store into a
  26162. diff -Nur linux-4.4.13.orig/lib/rbtree.c linux-4.4.13/lib/rbtree.c
  26163. --- linux-4.4.13.orig/lib/rbtree.c 2016-06-08 03:14:51.000000000 +0200
  26164. +++ linux-4.4.13/lib/rbtree.c 2016-06-22 21:55:08.074523867 +0200
  26165. @@ -23,6 +23,7 @@
  26166. #include <linux/rbtree_augmented.h>
  26167. #include <linux/export.h>
  26168. +#include <linux/rcupdate.h>
  26169. /*
  26170. * red-black trees properties: http://en.wikipedia.org/wiki/Rbtree
  26171. @@ -590,3 +591,13 @@
  26172. return rb_left_deepest_node(root->rb_node);
  26173. }
  26174. EXPORT_SYMBOL(rb_first_postorder);
  26175. +
  26176. +void rb_link_node_rcu(struct rb_node *node, struct rb_node *parent,
  26177. + struct rb_node **rb_link)
  26178. +{
  26179. + node->__rb_parent_color = (unsigned long)parent;
  26180. + node->rb_left = node->rb_right = NULL;
  26181. +
  26182. + rcu_assign_pointer(*rb_link, node);
  26183. +}
  26184. +EXPORT_SYMBOL(rb_link_node_rcu);
  26185. diff -Nur linux-4.4.13.orig/lib/scatterlist.c linux-4.4.13/lib/scatterlist.c
  26186. --- linux-4.4.13.orig/lib/scatterlist.c 2016-06-08 03:14:51.000000000 +0200
  26187. +++ linux-4.4.13/lib/scatterlist.c 2016-06-22 21:55:08.074523867 +0200
  26188. @@ -620,7 +620,7 @@
  26189. flush_kernel_dcache_page(miter->page);
  26190. if (miter->__flags & SG_MITER_ATOMIC) {
  26191. - WARN_ON_ONCE(preemptible());
  26192. + WARN_ON_ONCE(!pagefault_disabled());
  26193. kunmap_atomic(miter->addr);
  26194. } else
  26195. kunmap(miter->page);
  26196. @@ -664,7 +664,7 @@
  26197. if (!sg_miter_skip(&miter, skip))
  26198. return false;
  26199. - local_irq_save(flags);
  26200. + local_irq_save_nort(flags);
  26201. while (sg_miter_next(&miter) && offset < buflen) {
  26202. unsigned int len;
  26203. @@ -681,7 +681,7 @@
  26204. sg_miter_stop(&miter);
  26205. - local_irq_restore(flags);
  26206. + local_irq_restore_nort(flags);
  26207. return offset;
  26208. }
  26209. EXPORT_SYMBOL(sg_copy_buffer);
  26210. diff -Nur linux-4.4.13.orig/lib/smp_processor_id.c linux-4.4.13/lib/smp_processor_id.c
  26211. --- linux-4.4.13.orig/lib/smp_processor_id.c 2016-06-08 03:14:51.000000000 +0200
  26212. +++ linux-4.4.13/lib/smp_processor_id.c 2016-06-22 21:55:08.074523867 +0200
  26213. @@ -39,8 +39,9 @@
  26214. if (!printk_ratelimit())
  26215. goto out_enable;
  26216. - printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x] code: %s/%d\n",
  26217. - what1, what2, preempt_count() - 1, current->comm, current->pid);
  26218. + printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x %08x] code: %s/%d\n",
  26219. + what1, what2, preempt_count() - 1, __migrate_disabled(current),
  26220. + current->comm, current->pid);
  26221. print_symbol("caller is %s\n", (long)__builtin_return_address(0));
  26222. dump_stack();
  26223. diff -Nur linux-4.4.13.orig/Makefile linux-4.4.13/Makefile
  26224. --- linux-4.4.13.orig/Makefile 2016-06-08 03:14:51.000000000 +0200
  26225. +++ linux-4.4.13/Makefile 2016-06-22 21:55:08.074523867 +0200
  26226. @@ -768,6 +768,9 @@
  26227. # Prohibit date/time macros, which would make the build non-deterministic
  26228. KBUILD_CFLAGS += $(call cc-option,-Werror=date-time)
  26229. +# enforce correct pointer usage
  26230. +KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
  26231. +
  26232. # use the deterministic mode of AR if available
  26233. KBUILD_ARFLAGS := $(call ar-option,D)
  26234. diff -Nur linux-4.4.13.orig/mm/backing-dev.c linux-4.4.13/mm/backing-dev.c
  26235. --- linux-4.4.13.orig/mm/backing-dev.c 2016-06-08 03:14:51.000000000 +0200
  26236. +++ linux-4.4.13/mm/backing-dev.c 2016-06-22 21:55:08.074523867 +0200
  26237. @@ -457,9 +457,9 @@
  26238. {
  26239. unsigned long flags;
  26240. - local_irq_save(flags);
  26241. + local_irq_save_nort(flags);
  26242. if (!atomic_dec_and_lock(&congested->refcnt, &cgwb_lock)) {
  26243. - local_irq_restore(flags);
  26244. + local_irq_restore_nort(flags);
  26245. return;
  26246. }
  26247. diff -Nur linux-4.4.13.orig/mm/compaction.c linux-4.4.13/mm/compaction.c
  26248. --- linux-4.4.13.orig/mm/compaction.c 2016-06-08 03:14:51.000000000 +0200
  26249. +++ linux-4.4.13/mm/compaction.c 2016-06-22 21:55:08.074523867 +0200
  26250. @@ -1435,10 +1435,12 @@
  26251. cc->migrate_pfn & ~((1UL << cc->order) - 1);
  26252. if (cc->last_migrated_pfn < current_block_start) {
  26253. - cpu = get_cpu();
  26254. + cpu = get_cpu_light();
  26255. + local_lock_irq(swapvec_lock);
  26256. lru_add_drain_cpu(cpu);
  26257. + local_unlock_irq(swapvec_lock);
  26258. drain_local_pages(zone);
  26259. - put_cpu();
  26260. + put_cpu_light();
  26261. /* No more flushing until we migrate again */
  26262. cc->last_migrated_pfn = 0;
  26263. }
  26264. diff -Nur linux-4.4.13.orig/mm/filemap.c linux-4.4.13/mm/filemap.c
  26265. --- linux-4.4.13.orig/mm/filemap.c 2016-06-08 03:14:51.000000000 +0200
  26266. +++ linux-4.4.13/mm/filemap.c 2016-06-22 21:55:08.074523867 +0200
  26267. @@ -168,7 +168,9 @@
  26268. if (!workingset_node_pages(node) &&
  26269. list_empty(&node->private_list)) {
  26270. node->private_data = mapping;
  26271. - list_lru_add(&workingset_shadow_nodes, &node->private_list);
  26272. + local_lock(workingset_shadow_lock);
  26273. + list_lru_add(&__workingset_shadow_nodes, &node->private_list);
  26274. + local_unlock(workingset_shadow_lock);
  26275. }
  26276. }
  26277. @@ -597,9 +599,12 @@
  26278. * node->private_list is protected by
  26279. * mapping->tree_lock.
  26280. */
  26281. - if (!list_empty(&node->private_list))
  26282. - list_lru_del(&workingset_shadow_nodes,
  26283. + if (!list_empty(&node->private_list)) {
  26284. + local_lock(workingset_shadow_lock);
  26285. + list_lru_del(&__workingset_shadow_nodes,
  26286. &node->private_list);
  26287. + local_unlock(workingset_shadow_lock);
  26288. + }
  26289. }
  26290. return 0;
  26291. }
  26292. diff -Nur linux-4.4.13.orig/mm/highmem.c linux-4.4.13/mm/highmem.c
  26293. --- linux-4.4.13.orig/mm/highmem.c 2016-06-08 03:14:51.000000000 +0200
  26294. +++ linux-4.4.13/mm/highmem.c 2016-06-22 21:55:08.074523867 +0200
  26295. @@ -29,10 +29,11 @@
  26296. #include <linux/kgdb.h>
  26297. #include <asm/tlbflush.h>
  26298. -
  26299. +#ifndef CONFIG_PREEMPT_RT_FULL
  26300. #if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
  26301. DEFINE_PER_CPU(int, __kmap_atomic_idx);
  26302. #endif
  26303. +#endif
  26304. /*
  26305. * Virtual_count is not a pure "count".
  26306. @@ -107,8 +108,9 @@
  26307. unsigned long totalhigh_pages __read_mostly;
  26308. EXPORT_SYMBOL(totalhigh_pages);
  26309. -
  26310. +#ifndef CONFIG_PREEMPT_RT_FULL
  26311. EXPORT_PER_CPU_SYMBOL(__kmap_atomic_idx);
  26312. +#endif
  26313. unsigned int nr_free_highpages (void)
  26314. {
  26315. diff -Nur linux-4.4.13.orig/mm/Kconfig linux-4.4.13/mm/Kconfig
  26316. --- linux-4.4.13.orig/mm/Kconfig 2016-06-08 03:14:51.000000000 +0200
  26317. +++ linux-4.4.13/mm/Kconfig 2016-06-22 21:55:08.074523867 +0200
  26318. @@ -392,7 +392,7 @@
  26319. config TRANSPARENT_HUGEPAGE
  26320. bool "Transparent Hugepage Support"
  26321. - depends on HAVE_ARCH_TRANSPARENT_HUGEPAGE
  26322. + depends on HAVE_ARCH_TRANSPARENT_HUGEPAGE && !PREEMPT_RT_FULL
  26323. select COMPACTION
  26324. help
  26325. Transparent Hugepages allows the kernel to use huge pages and
  26326. diff -Nur linux-4.4.13.orig/mm/memcontrol.c linux-4.4.13/mm/memcontrol.c
  26327. --- linux-4.4.13.orig/mm/memcontrol.c 2016-06-08 03:14:51.000000000 +0200
  26328. +++ linux-4.4.13/mm/memcontrol.c 2016-06-22 21:55:08.074523867 +0200
  26329. @@ -67,6 +67,8 @@
  26330. #include <net/sock.h>
  26331. #include <net/ip.h>
  26332. #include <net/tcp_memcontrol.h>
  26333. +#include <linux/locallock.h>
  26334. +
  26335. #include "slab.h"
  26336. #include <asm/uaccess.h>
  26337. @@ -87,6 +89,7 @@
  26338. #define do_swap_account 0
  26339. #endif
  26340. +static DEFINE_LOCAL_IRQ_LOCK(event_lock);
  26341. static const char * const mem_cgroup_stat_names[] = {
  26342. "cache",
  26343. "rss",
  26344. @@ -1936,14 +1939,17 @@
  26345. */
  26346. static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
  26347. {
  26348. - struct memcg_stock_pcp *stock = &get_cpu_var(memcg_stock);
  26349. + struct memcg_stock_pcp *stock;
  26350. + int cpu = get_cpu_light();
  26351. +
  26352. + stock = &per_cpu(memcg_stock, cpu);
  26353. if (stock->cached != memcg) { /* reset if necessary */
  26354. drain_stock(stock);
  26355. stock->cached = memcg;
  26356. }
  26357. stock->nr_pages += nr_pages;
  26358. - put_cpu_var(memcg_stock);
  26359. + put_cpu_light();
  26360. }
  26361. /*
  26362. @@ -1959,7 +1965,7 @@
  26363. return;
  26364. /* Notify other cpus that system-wide "drain" is running */
  26365. get_online_cpus();
  26366. - curcpu = get_cpu();
  26367. + curcpu = get_cpu_light();
  26368. for_each_online_cpu(cpu) {
  26369. struct memcg_stock_pcp *stock = &per_cpu(memcg_stock, cpu);
  26370. struct mem_cgroup *memcg;
  26371. @@ -1976,7 +1982,7 @@
  26372. schedule_work_on(cpu, &stock->work);
  26373. }
  26374. }
  26375. - put_cpu();
  26376. + put_cpu_light();
  26377. put_online_cpus();
  26378. mutex_unlock(&percpu_charge_mutex);
  26379. }
  26380. @@ -4618,12 +4624,12 @@
  26381. ret = 0;
  26382. - local_irq_disable();
  26383. + local_lock_irq(event_lock);
  26384. mem_cgroup_charge_statistics(to, page, nr_pages);
  26385. memcg_check_events(to, page);
  26386. mem_cgroup_charge_statistics(from, page, -nr_pages);
  26387. memcg_check_events(from, page);
  26388. - local_irq_enable();
  26389. + local_unlock_irq(event_lock);
  26390. out_unlock:
  26391. unlock_page(page);
  26392. out:
  26393. @@ -5411,10 +5417,10 @@
  26394. VM_BUG_ON_PAGE(!PageTransHuge(page), page);
  26395. }
  26396. - local_irq_disable();
  26397. + local_lock_irq(event_lock);
  26398. mem_cgroup_charge_statistics(memcg, page, nr_pages);
  26399. memcg_check_events(memcg, page);
  26400. - local_irq_enable();
  26401. + local_unlock_irq(event_lock);
  26402. if (do_swap_account && PageSwapCache(page)) {
  26403. swp_entry_t entry = { .val = page_private(page) };
  26404. @@ -5470,14 +5476,14 @@
  26405. memcg_oom_recover(memcg);
  26406. }
  26407. - local_irq_save(flags);
  26408. + local_lock_irqsave(event_lock, flags);
  26409. __this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_RSS], nr_anon);
  26410. __this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_CACHE], nr_file);
  26411. __this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_RSS_HUGE], nr_huge);
  26412. __this_cpu_add(memcg->stat->events[MEM_CGROUP_EVENTS_PGPGOUT], pgpgout);
  26413. __this_cpu_add(memcg->stat->nr_page_events, nr_pages);
  26414. memcg_check_events(memcg, dummy_page);
  26415. - local_irq_restore(flags);
  26416. + local_unlock_irqrestore(event_lock, flags);
  26417. if (!mem_cgroup_is_root(memcg))
  26418. css_put_many(&memcg->css, nr_pages);
  26419. @@ -5669,6 +5675,7 @@
  26420. {
  26421. struct mem_cgroup *memcg;
  26422. unsigned short oldid;
  26423. + unsigned long flags;
  26424. VM_BUG_ON_PAGE(PageLRU(page), page);
  26425. VM_BUG_ON_PAGE(page_count(page), page);
  26426. @@ -5697,9 +5704,13 @@
  26427. * important here to have the interrupts disabled because it is the
  26428. * only synchronisation we have for udpating the per-CPU variables.
  26429. */
  26430. + local_lock_irqsave(event_lock, flags);
  26431. +#ifndef CONFIG_PREEMPT_RT_BASE
  26432. VM_BUG_ON(!irqs_disabled());
  26433. +#endif
  26434. mem_cgroup_charge_statistics(memcg, page, -1);
  26435. memcg_check_events(memcg, page);
  26436. + local_unlock_irqrestore(event_lock, flags);
  26437. }
  26438. /**
  26439. diff -Nur linux-4.4.13.orig/mm/mmu_context.c linux-4.4.13/mm/mmu_context.c
  26440. --- linux-4.4.13.orig/mm/mmu_context.c 2016-06-08 03:14:51.000000000 +0200
  26441. +++ linux-4.4.13/mm/mmu_context.c 2016-06-22 21:55:08.074523867 +0200
  26442. @@ -23,6 +23,7 @@
  26443. struct task_struct *tsk = current;
  26444. task_lock(tsk);
  26445. + preempt_disable_rt();
  26446. active_mm = tsk->active_mm;
  26447. if (active_mm != mm) {
  26448. atomic_inc(&mm->mm_count);
  26449. @@ -30,6 +31,7 @@
  26450. }
  26451. tsk->mm = mm;
  26452. switch_mm(active_mm, mm, tsk);
  26453. + preempt_enable_rt();
  26454. task_unlock(tsk);
  26455. #ifdef finish_arch_post_lock_switch
  26456. finish_arch_post_lock_switch();
  26457. diff -Nur linux-4.4.13.orig/mm/page_alloc.c linux-4.4.13/mm/page_alloc.c
  26458. --- linux-4.4.13.orig/mm/page_alloc.c 2016-06-08 03:14:51.000000000 +0200
  26459. +++ linux-4.4.13/mm/page_alloc.c 2016-06-22 21:55:08.078523867 +0200
  26460. @@ -60,6 +60,7 @@
  26461. #include <linux/page_ext.h>
  26462. #include <linux/hugetlb.h>
  26463. #include <linux/sched/rt.h>
  26464. +#include <linux/locallock.h>
  26465. #include <linux/page_owner.h>
  26466. #include <linux/kthread.h>
  26467. @@ -264,6 +265,18 @@
  26468. EXPORT_SYMBOL(nr_online_nodes);
  26469. #endif
  26470. +static DEFINE_LOCAL_IRQ_LOCK(pa_lock);
  26471. +
  26472. +#ifdef CONFIG_PREEMPT_RT_BASE
  26473. +# define cpu_lock_irqsave(cpu, flags) \
  26474. + local_lock_irqsave_on(pa_lock, flags, cpu)
  26475. +# define cpu_unlock_irqrestore(cpu, flags) \
  26476. + local_unlock_irqrestore_on(pa_lock, flags, cpu)
  26477. +#else
  26478. +# define cpu_lock_irqsave(cpu, flags) local_irq_save(flags)
  26479. +# define cpu_unlock_irqrestore(cpu, flags) local_irq_restore(flags)
  26480. +#endif
  26481. +
  26482. int page_group_by_mobility_disabled __read_mostly;
  26483. #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
  26484. @@ -784,7 +797,7 @@
  26485. }
  26486. /*
  26487. - * Frees a number of pages from the PCP lists
  26488. + * Frees a number of pages which have been collected from the pcp lists.
  26489. * Assumes all pages on list are in same zone, and of same order.
  26490. * count is the number of pages to free.
  26491. *
  26492. @@ -795,18 +808,53 @@
  26493. * pinned" detection logic.
  26494. */
  26495. static void free_pcppages_bulk(struct zone *zone, int count,
  26496. - struct per_cpu_pages *pcp)
  26497. + struct list_head *list)
  26498. {
  26499. - int migratetype = 0;
  26500. - int batch_free = 0;
  26501. int to_free = count;
  26502. unsigned long nr_scanned;
  26503. + unsigned long flags;
  26504. +
  26505. + spin_lock_irqsave(&zone->lock, flags);
  26506. - spin_lock(&zone->lock);
  26507. nr_scanned = zone_page_state(zone, NR_PAGES_SCANNED);
  26508. if (nr_scanned)
  26509. __mod_zone_page_state(zone, NR_PAGES_SCANNED, -nr_scanned);
  26510. + while (!list_empty(list)) {
  26511. + struct page *page = list_first_entry(list, struct page, lru);
  26512. + int mt; /* migratetype of the to-be-freed page */
  26513. +
  26514. + /* must delete as __free_one_page list manipulates */
  26515. + list_del(&page->lru);
  26516. +
  26517. + mt = get_pcppage_migratetype(page);
  26518. + /* MIGRATE_ISOLATE page should not go to pcplists */
  26519. + VM_BUG_ON_PAGE(is_migrate_isolate(mt), page);
  26520. + /* Pageblock could have been isolated meanwhile */
  26521. + if (unlikely(has_isolate_pageblock(zone)))
  26522. + mt = get_pageblock_migratetype(page);
  26523. +
  26524. + __free_one_page(page, page_to_pfn(page), zone, 0, mt);
  26525. + trace_mm_page_pcpu_drain(page, 0, mt);
  26526. + to_free--;
  26527. + }
  26528. + WARN_ON(to_free != 0);
  26529. + spin_unlock_irqrestore(&zone->lock, flags);
  26530. +}
  26531. +
  26532. +/*
  26533. + * Moves a number of pages from the PCP lists to free list which
  26534. + * is freed outside of the locked region.
  26535. + *
  26536. + * Assumes all pages on list are in same zone, and of same order.
  26537. + * count is the number of pages to free.
  26538. + */
  26539. +static void isolate_pcp_pages(int to_free, struct per_cpu_pages *src,
  26540. + struct list_head *dst)
  26541. +{
  26542. + int migratetype = 0;
  26543. + int batch_free = 0;
  26544. +
  26545. while (to_free) {
  26546. struct page *page;
  26547. struct list_head *list;
  26548. @@ -822,7 +870,7 @@
  26549. batch_free++;
  26550. if (++migratetype == MIGRATE_PCPTYPES)
  26551. migratetype = 0;
  26552. - list = &pcp->lists[migratetype];
  26553. + list = &src->lists[migratetype];
  26554. } while (list_empty(list));
  26555. /* This is the only non-empty list. Free them all. */
  26556. @@ -830,24 +878,12 @@
  26557. batch_free = to_free;
  26558. do {
  26559. - int mt; /* migratetype of the to-be-freed page */
  26560. -
  26561. - page = list_entry(list->prev, struct page, lru);
  26562. - /* must delete as __free_one_page list manipulates */
  26563. + page = list_last_entry(list, struct page, lru);
  26564. list_del(&page->lru);
  26565. - mt = get_pcppage_migratetype(page);
  26566. - /* MIGRATE_ISOLATE page should not go to pcplists */
  26567. - VM_BUG_ON_PAGE(is_migrate_isolate(mt), page);
  26568. - /* Pageblock could have been isolated meanwhile */
  26569. - if (unlikely(has_isolate_pageblock(zone)))
  26570. - mt = get_pageblock_migratetype(page);
  26571. -
  26572. - __free_one_page(page, page_to_pfn(page), zone, 0, mt);
  26573. - trace_mm_page_pcpu_drain(page, 0, mt);
  26574. + list_add(&page->lru, dst);
  26575. } while (--to_free && --batch_free && !list_empty(list));
  26576. }
  26577. - spin_unlock(&zone->lock);
  26578. }
  26579. static void free_one_page(struct zone *zone,
  26580. @@ -856,7 +892,9 @@
  26581. int migratetype)
  26582. {
  26583. unsigned long nr_scanned;
  26584. - spin_lock(&zone->lock);
  26585. + unsigned long flags;
  26586. +
  26587. + spin_lock_irqsave(&zone->lock, flags);
  26588. nr_scanned = zone_page_state(zone, NR_PAGES_SCANNED);
  26589. if (nr_scanned)
  26590. __mod_zone_page_state(zone, NR_PAGES_SCANNED, -nr_scanned);
  26591. @@ -866,7 +904,7 @@
  26592. migratetype = get_pfnblock_migratetype(page, pfn);
  26593. }
  26594. __free_one_page(page, pfn, zone, order, migratetype);
  26595. - spin_unlock(&zone->lock);
  26596. + spin_unlock_irqrestore(&zone->lock, flags);
  26597. }
  26598. static int free_tail_pages_check(struct page *head_page, struct page *page)
  26599. @@ -1017,10 +1055,10 @@
  26600. return;
  26601. migratetype = get_pfnblock_migratetype(page, pfn);
  26602. - local_irq_save(flags);
  26603. + local_lock_irqsave(pa_lock, flags);
  26604. __count_vm_events(PGFREE, 1 << order);
  26605. free_one_page(page_zone(page), page, pfn, order, migratetype);
  26606. - local_irq_restore(flags);
  26607. + local_unlock_irqrestore(pa_lock, flags);
  26608. }
  26609. static void __init __free_pages_boot_core(struct page *page,
  26610. @@ -1877,16 +1915,18 @@
  26611. void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp)
  26612. {
  26613. unsigned long flags;
  26614. + LIST_HEAD(dst);
  26615. int to_drain, batch;
  26616. - local_irq_save(flags);
  26617. + local_lock_irqsave(pa_lock, flags);
  26618. batch = READ_ONCE(pcp->batch);
  26619. to_drain = min(pcp->count, batch);
  26620. if (to_drain > 0) {
  26621. - free_pcppages_bulk(zone, to_drain, pcp);
  26622. + isolate_pcp_pages(to_drain, pcp, &dst);
  26623. pcp->count -= to_drain;
  26624. }
  26625. - local_irq_restore(flags);
  26626. + local_unlock_irqrestore(pa_lock, flags);
  26627. + free_pcppages_bulk(zone, to_drain, &dst);
  26628. }
  26629. #endif
  26630. @@ -1902,16 +1942,21 @@
  26631. unsigned long flags;
  26632. struct per_cpu_pageset *pset;
  26633. struct per_cpu_pages *pcp;
  26634. + LIST_HEAD(dst);
  26635. + int count;
  26636. - local_irq_save(flags);
  26637. + cpu_lock_irqsave(cpu, flags);
  26638. pset = per_cpu_ptr(zone->pageset, cpu);
  26639. pcp = &pset->pcp;
  26640. - if (pcp->count) {
  26641. - free_pcppages_bulk(zone, pcp->count, pcp);
  26642. + count = pcp->count;
  26643. + if (count) {
  26644. + isolate_pcp_pages(count, pcp, &dst);
  26645. pcp->count = 0;
  26646. }
  26647. - local_irq_restore(flags);
  26648. + cpu_unlock_irqrestore(cpu, flags);
  26649. + if (count)
  26650. + free_pcppages_bulk(zone, count, &dst);
  26651. }
  26652. /*
  26653. @@ -1997,8 +2042,17 @@
  26654. else
  26655. cpumask_clear_cpu(cpu, &cpus_with_pcps);
  26656. }
  26657. +#ifndef CONFIG_PREEMPT_RT_BASE
  26658. on_each_cpu_mask(&cpus_with_pcps, (smp_call_func_t) drain_local_pages,
  26659. zone, 1);
  26660. +#else
  26661. + for_each_cpu(cpu, &cpus_with_pcps) {
  26662. + if (zone)
  26663. + drain_pages_zone(cpu, zone);
  26664. + else
  26665. + drain_pages(cpu);
  26666. + }
  26667. +#endif
  26668. }
  26669. #ifdef CONFIG_HIBERNATION
  26670. @@ -2054,7 +2108,7 @@
  26671. migratetype = get_pfnblock_migratetype(page, pfn);
  26672. set_pcppage_migratetype(page, migratetype);
  26673. - local_irq_save(flags);
  26674. + local_lock_irqsave(pa_lock, flags);
  26675. __count_vm_event(PGFREE);
  26676. /*
  26677. @@ -2080,12 +2134,17 @@
  26678. pcp->count++;
  26679. if (pcp->count >= pcp->high) {
  26680. unsigned long batch = READ_ONCE(pcp->batch);
  26681. - free_pcppages_bulk(zone, batch, pcp);
  26682. + LIST_HEAD(dst);
  26683. +
  26684. + isolate_pcp_pages(batch, pcp, &dst);
  26685. pcp->count -= batch;
  26686. + local_unlock_irqrestore(pa_lock, flags);
  26687. + free_pcppages_bulk(zone, batch, &dst);
  26688. + return;
  26689. }
  26690. out:
  26691. - local_irq_restore(flags);
  26692. + local_unlock_irqrestore(pa_lock, flags);
  26693. }
  26694. /*
  26695. @@ -2220,7 +2279,7 @@
  26696. struct per_cpu_pages *pcp;
  26697. struct list_head *list;
  26698. - local_irq_save(flags);
  26699. + local_lock_irqsave(pa_lock, flags);
  26700. pcp = &this_cpu_ptr(zone->pageset)->pcp;
  26701. list = &pcp->lists[migratetype];
  26702. if (list_empty(list)) {
  26703. @@ -2252,7 +2311,7 @@
  26704. */
  26705. WARN_ON_ONCE(order > 1);
  26706. }
  26707. - spin_lock_irqsave(&zone->lock, flags);
  26708. + local_spin_lock_irqsave(pa_lock, &zone->lock, flags);
  26709. page = NULL;
  26710. if (alloc_flags & ALLOC_HARDER) {
  26711. @@ -2262,11 +2321,13 @@
  26712. }
  26713. if (!page)
  26714. page = __rmqueue(zone, order, migratetype, gfp_flags);
  26715. - spin_unlock(&zone->lock);
  26716. - if (!page)
  26717. + if (!page) {
  26718. + spin_unlock(&zone->lock);
  26719. goto failed;
  26720. + }
  26721. __mod_zone_freepage_state(zone, -(1 << order),
  26722. get_pcppage_migratetype(page));
  26723. + spin_unlock(&zone->lock);
  26724. }
  26725. __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
  26726. @@ -2276,13 +2337,13 @@
  26727. __count_zone_vm_events(PGALLOC, zone, 1 << order);
  26728. zone_statistics(preferred_zone, zone, gfp_flags);
  26729. - local_irq_restore(flags);
  26730. + local_unlock_irqrestore(pa_lock, flags);
  26731. VM_BUG_ON_PAGE(bad_range(zone, page), page);
  26732. return page;
  26733. failed:
  26734. - local_irq_restore(flags);
  26735. + local_unlock_irqrestore(pa_lock, flags);
  26736. return NULL;
  26737. }
  26738. @@ -5948,6 +6009,7 @@
  26739. void __init page_alloc_init(void)
  26740. {
  26741. hotcpu_notifier(page_alloc_cpu_notify, 0);
  26742. + local_irq_lock_init(pa_lock);
  26743. }
  26744. /*
  26745. @@ -6842,7 +6904,7 @@
  26746. struct per_cpu_pageset *pset;
  26747. /* avoid races with drain_pages() */
  26748. - local_irq_save(flags);
  26749. + local_lock_irqsave(pa_lock, flags);
  26750. if (zone->pageset != &boot_pageset) {
  26751. for_each_online_cpu(cpu) {
  26752. pset = per_cpu_ptr(zone->pageset, cpu);
  26753. @@ -6851,7 +6913,7 @@
  26754. free_percpu(zone->pageset);
  26755. zone->pageset = &boot_pageset;
  26756. }
  26757. - local_irq_restore(flags);
  26758. + local_unlock_irqrestore(pa_lock, flags);
  26759. }
  26760. #ifdef CONFIG_MEMORY_HOTREMOVE
  26761. diff -Nur linux-4.4.13.orig/mm/slab.h linux-4.4.13/mm/slab.h
  26762. --- linux-4.4.13.orig/mm/slab.h 2016-06-08 03:14:51.000000000 +0200
  26763. +++ linux-4.4.13/mm/slab.h 2016-06-22 21:55:08.078523867 +0200
  26764. @@ -324,7 +324,11 @@
  26765. * The slab lists for all objects.
  26766. */
  26767. struct kmem_cache_node {
  26768. +#ifdef CONFIG_SLUB
  26769. + raw_spinlock_t list_lock;
  26770. +#else
  26771. spinlock_t list_lock;
  26772. +#endif
  26773. #ifdef CONFIG_SLAB
  26774. struct list_head slabs_partial; /* partial list first, better asm code */
  26775. diff -Nur linux-4.4.13.orig/mm/slub.c linux-4.4.13/mm/slub.c
  26776. --- linux-4.4.13.orig/mm/slub.c 2016-06-08 03:14:51.000000000 +0200
  26777. +++ linux-4.4.13/mm/slub.c 2016-06-22 21:55:08.078523867 +0200
  26778. @@ -1075,7 +1075,7 @@
  26779. void *object = head;
  26780. int cnt = 0;
  26781. - spin_lock_irqsave(&n->list_lock, *flags);
  26782. + raw_spin_lock_irqsave(&n->list_lock, *flags);
  26783. slab_lock(page);
  26784. if (!check_slab(s, page))
  26785. @@ -1136,7 +1136,7 @@
  26786. fail:
  26787. slab_unlock(page);
  26788. - spin_unlock_irqrestore(&n->list_lock, *flags);
  26789. + raw_spin_unlock_irqrestore(&n->list_lock, *flags);
  26790. slab_fix(s, "Object at 0x%p not freed", object);
  26791. return NULL;
  26792. }
  26793. @@ -1263,6 +1263,12 @@
  26794. #endif /* CONFIG_SLUB_DEBUG */
  26795. +struct slub_free_list {
  26796. + raw_spinlock_t lock;
  26797. + struct list_head list;
  26798. +};
  26799. +static DEFINE_PER_CPU(struct slub_free_list, slub_free_list);
  26800. +
  26801. /*
  26802. * Hooks for other subsystems that check memory allocations. In a typical
  26803. * production configuration these hooks all should produce no code at all.
  26804. @@ -1399,10 +1405,17 @@
  26805. gfp_t alloc_gfp;
  26806. void *start, *p;
  26807. int idx, order;
  26808. + bool enableirqs = false;
  26809. flags &= gfp_allowed_mask;
  26810. if (gfpflags_allow_blocking(flags))
  26811. + enableirqs = true;
  26812. +#ifdef CONFIG_PREEMPT_RT_FULL
  26813. + if (system_state == SYSTEM_RUNNING)
  26814. + enableirqs = true;
  26815. +#endif
  26816. + if (enableirqs)
  26817. local_irq_enable();
  26818. flags |= s->allocflags;
  26819. @@ -1473,7 +1486,7 @@
  26820. page->frozen = 1;
  26821. out:
  26822. - if (gfpflags_allow_blocking(flags))
  26823. + if (enableirqs)
  26824. local_irq_disable();
  26825. if (!page)
  26826. return NULL;
  26827. @@ -1529,6 +1542,16 @@
  26828. __free_kmem_pages(page, order);
  26829. }
  26830. +static void free_delayed(struct list_head *h)
  26831. +{
  26832. + while(!list_empty(h)) {
  26833. + struct page *page = list_first_entry(h, struct page, lru);
  26834. +
  26835. + list_del(&page->lru);
  26836. + __free_slab(page->slab_cache, page);
  26837. + }
  26838. +}
  26839. +
  26840. #define need_reserve_slab_rcu \
  26841. (sizeof(((struct page *)NULL)->lru) < sizeof(struct rcu_head))
  26842. @@ -1560,6 +1583,12 @@
  26843. }
  26844. call_rcu(head, rcu_free_slab);
  26845. + } else if (irqs_disabled()) {
  26846. + struct slub_free_list *f = this_cpu_ptr(&slub_free_list);
  26847. +
  26848. + raw_spin_lock(&f->lock);
  26849. + list_add(&page->lru, &f->list);
  26850. + raw_spin_unlock(&f->lock);
  26851. } else
  26852. __free_slab(s, page);
  26853. }
  26854. @@ -1673,7 +1702,7 @@
  26855. if (!n || !n->nr_partial)
  26856. return NULL;
  26857. - spin_lock(&n->list_lock);
  26858. + raw_spin_lock(&n->list_lock);
  26859. list_for_each_entry_safe(page, page2, &n->partial, lru) {
  26860. void *t;
  26861. @@ -1698,7 +1727,7 @@
  26862. break;
  26863. }
  26864. - spin_unlock(&n->list_lock);
  26865. + raw_spin_unlock(&n->list_lock);
  26866. return object;
  26867. }
  26868. @@ -1944,7 +1973,7 @@
  26869. * that acquire_slab() will see a slab page that
  26870. * is frozen
  26871. */
  26872. - spin_lock(&n->list_lock);
  26873. + raw_spin_lock(&n->list_lock);
  26874. }
  26875. } else {
  26876. m = M_FULL;
  26877. @@ -1955,7 +1984,7 @@
  26878. * slabs from diagnostic functions will not see
  26879. * any frozen slabs.
  26880. */
  26881. - spin_lock(&n->list_lock);
  26882. + raw_spin_lock(&n->list_lock);
  26883. }
  26884. }
  26885. @@ -1990,7 +2019,7 @@
  26886. goto redo;
  26887. if (lock)
  26888. - spin_unlock(&n->list_lock);
  26889. + raw_spin_unlock(&n->list_lock);
  26890. if (m == M_FREE) {
  26891. stat(s, DEACTIVATE_EMPTY);
  26892. @@ -2022,10 +2051,10 @@
  26893. n2 = get_node(s, page_to_nid(page));
  26894. if (n != n2) {
  26895. if (n)
  26896. - spin_unlock(&n->list_lock);
  26897. + raw_spin_unlock(&n->list_lock);
  26898. n = n2;
  26899. - spin_lock(&n->list_lock);
  26900. + raw_spin_lock(&n->list_lock);
  26901. }
  26902. do {
  26903. @@ -2054,7 +2083,7 @@
  26904. }
  26905. if (n)
  26906. - spin_unlock(&n->list_lock);
  26907. + raw_spin_unlock(&n->list_lock);
  26908. while (discard_page) {
  26909. page = discard_page;
  26910. @@ -2093,14 +2122,21 @@
  26911. pobjects = oldpage->pobjects;
  26912. pages = oldpage->pages;
  26913. if (drain && pobjects > s->cpu_partial) {
  26914. + struct slub_free_list *f;
  26915. unsigned long flags;
  26916. + LIST_HEAD(tofree);
  26917. /*
  26918. * partial array is full. Move the existing
  26919. * set to the per node partial list.
  26920. */
  26921. local_irq_save(flags);
  26922. unfreeze_partials(s, this_cpu_ptr(s->cpu_slab));
  26923. + f = this_cpu_ptr(&slub_free_list);
  26924. + raw_spin_lock(&f->lock);
  26925. + list_splice_init(&f->list, &tofree);
  26926. + raw_spin_unlock(&f->lock);
  26927. local_irq_restore(flags);
  26928. + free_delayed(&tofree);
  26929. oldpage = NULL;
  26930. pobjects = 0;
  26931. pages = 0;
  26932. @@ -2172,7 +2208,22 @@
  26933. static void flush_all(struct kmem_cache *s)
  26934. {
  26935. + LIST_HEAD(tofree);
  26936. + int cpu;
  26937. +
  26938. on_each_cpu_cond(has_cpu_slab, flush_cpu_slab, s, 1, GFP_ATOMIC);
  26939. + for_each_online_cpu(cpu) {
  26940. + struct slub_free_list *f;
  26941. +
  26942. + if (!has_cpu_slab(cpu, s))
  26943. + continue;
  26944. +
  26945. + f = &per_cpu(slub_free_list, cpu);
  26946. + raw_spin_lock_irq(&f->lock);
  26947. + list_splice_init(&f->list, &tofree);
  26948. + raw_spin_unlock_irq(&f->lock);
  26949. + free_delayed(&tofree);
  26950. + }
  26951. }
  26952. /*
  26953. @@ -2208,10 +2259,10 @@
  26954. unsigned long x = 0;
  26955. struct page *page;
  26956. - spin_lock_irqsave(&n->list_lock, flags);
  26957. + raw_spin_lock_irqsave(&n->list_lock, flags);
  26958. list_for_each_entry(page, &n->partial, lru)
  26959. x += get_count(page);
  26960. - spin_unlock_irqrestore(&n->list_lock, flags);
  26961. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  26962. return x;
  26963. }
  26964. #endif /* CONFIG_SLUB_DEBUG || CONFIG_SYSFS */
  26965. @@ -2349,8 +2400,10 @@
  26966. * already disabled (which is the case for bulk allocation).
  26967. */
  26968. static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
  26969. - unsigned long addr, struct kmem_cache_cpu *c)
  26970. + unsigned long addr, struct kmem_cache_cpu *c,
  26971. + struct list_head *to_free)
  26972. {
  26973. + struct slub_free_list *f;
  26974. void *freelist;
  26975. struct page *page;
  26976. @@ -2410,6 +2463,13 @@
  26977. VM_BUG_ON(!c->page->frozen);
  26978. c->freelist = get_freepointer(s, freelist);
  26979. c->tid = next_tid(c->tid);
  26980. +
  26981. +out:
  26982. + f = this_cpu_ptr(&slub_free_list);
  26983. + raw_spin_lock(&f->lock);
  26984. + list_splice_init(&f->list, to_free);
  26985. + raw_spin_unlock(&f->lock);
  26986. +
  26987. return freelist;
  26988. new_slab:
  26989. @@ -2441,7 +2501,7 @@
  26990. deactivate_slab(s, page, get_freepointer(s, freelist));
  26991. c->page = NULL;
  26992. c->freelist = NULL;
  26993. - return freelist;
  26994. + goto out;
  26995. }
  26996. /*
  26997. @@ -2453,6 +2513,7 @@
  26998. {
  26999. void *p;
  27000. unsigned long flags;
  27001. + LIST_HEAD(tofree);
  27002. local_irq_save(flags);
  27003. #ifdef CONFIG_PREEMPT
  27004. @@ -2464,8 +2525,9 @@
  27005. c = this_cpu_ptr(s->cpu_slab);
  27006. #endif
  27007. - p = ___slab_alloc(s, gfpflags, node, addr, c);
  27008. + p = ___slab_alloc(s, gfpflags, node, addr, c, &tofree);
  27009. local_irq_restore(flags);
  27010. + free_delayed(&tofree);
  27011. return p;
  27012. }
  27013. @@ -2652,7 +2714,7 @@
  27014. do {
  27015. if (unlikely(n)) {
  27016. - spin_unlock_irqrestore(&n->list_lock, flags);
  27017. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  27018. n = NULL;
  27019. }
  27020. prior = page->freelist;
  27021. @@ -2684,7 +2746,7 @@
  27022. * Otherwise the list_lock will synchronize with
  27023. * other processors updating the list of slabs.
  27024. */
  27025. - spin_lock_irqsave(&n->list_lock, flags);
  27026. + raw_spin_lock_irqsave(&n->list_lock, flags);
  27027. }
  27028. }
  27029. @@ -2726,7 +2788,7 @@
  27030. add_partial(n, page, DEACTIVATE_TO_TAIL);
  27031. stat(s, FREE_ADD_PARTIAL);
  27032. }
  27033. - spin_unlock_irqrestore(&n->list_lock, flags);
  27034. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  27035. return;
  27036. slab_empty:
  27037. @@ -2741,7 +2803,7 @@
  27038. remove_full(s, n, page);
  27039. }
  27040. - spin_unlock_irqrestore(&n->list_lock, flags);
  27041. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  27042. stat(s, FREE_SLAB);
  27043. discard_slab(s, page);
  27044. }
  27045. @@ -2913,6 +2975,7 @@
  27046. void **p)
  27047. {
  27048. struct kmem_cache_cpu *c;
  27049. + LIST_HEAD(to_free);
  27050. int i;
  27051. /* memcg and kmem_cache debug support */
  27052. @@ -2936,7 +2999,7 @@
  27053. * of re-populating per CPU c->freelist
  27054. */
  27055. p[i] = ___slab_alloc(s, flags, NUMA_NO_NODE,
  27056. - _RET_IP_, c);
  27057. + _RET_IP_, c, &to_free);
  27058. if (unlikely(!p[i]))
  27059. goto error;
  27060. @@ -2948,6 +3011,7 @@
  27061. }
  27062. c->tid = next_tid(c->tid);
  27063. local_irq_enable();
  27064. + free_delayed(&to_free);
  27065. /* Clear memory outside IRQ disabled fastpath loop */
  27066. if (unlikely(flags & __GFP_ZERO)) {
  27067. @@ -3095,7 +3159,7 @@
  27068. init_kmem_cache_node(struct kmem_cache_node *n)
  27069. {
  27070. n->nr_partial = 0;
  27071. - spin_lock_init(&n->list_lock);
  27072. + raw_spin_lock_init(&n->list_lock);
  27073. INIT_LIST_HEAD(&n->partial);
  27074. #ifdef CONFIG_SLUB_DEBUG
  27075. atomic_long_set(&n->nr_slabs, 0);
  27076. @@ -3677,7 +3741,7 @@
  27077. for (i = 0; i < SHRINK_PROMOTE_MAX; i++)
  27078. INIT_LIST_HEAD(promote + i);
  27079. - spin_lock_irqsave(&n->list_lock, flags);
  27080. + raw_spin_lock_irqsave(&n->list_lock, flags);
  27081. /*
  27082. * Build lists of slabs to discard or promote.
  27083. @@ -3708,7 +3772,7 @@
  27084. for (i = SHRINK_PROMOTE_MAX - 1; i >= 0; i--)
  27085. list_splice(promote + i, &n->partial);
  27086. - spin_unlock_irqrestore(&n->list_lock, flags);
  27087. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  27088. /* Release empty slabs */
  27089. list_for_each_entry_safe(page, t, &discard, lru)
  27090. @@ -3884,6 +3948,12 @@
  27091. {
  27092. static __initdata struct kmem_cache boot_kmem_cache,
  27093. boot_kmem_cache_node;
  27094. + int cpu;
  27095. +
  27096. + for_each_possible_cpu(cpu) {
  27097. + raw_spin_lock_init(&per_cpu(slub_free_list, cpu).lock);
  27098. + INIT_LIST_HEAD(&per_cpu(slub_free_list, cpu).list);
  27099. + }
  27100. if (debug_guardpage_minorder())
  27101. slub_max_order = 0;
  27102. @@ -4127,7 +4197,7 @@
  27103. struct page *page;
  27104. unsigned long flags;
  27105. - spin_lock_irqsave(&n->list_lock, flags);
  27106. + raw_spin_lock_irqsave(&n->list_lock, flags);
  27107. list_for_each_entry(page, &n->partial, lru) {
  27108. validate_slab_slab(s, page, map);
  27109. @@ -4149,7 +4219,7 @@
  27110. s->name, count, atomic_long_read(&n->nr_slabs));
  27111. out:
  27112. - spin_unlock_irqrestore(&n->list_lock, flags);
  27113. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  27114. return count;
  27115. }
  27116. @@ -4337,12 +4407,12 @@
  27117. if (!atomic_long_read(&n->nr_slabs))
  27118. continue;
  27119. - spin_lock_irqsave(&n->list_lock, flags);
  27120. + raw_spin_lock_irqsave(&n->list_lock, flags);
  27121. list_for_each_entry(page, &n->partial, lru)
  27122. process_slab(&t, s, page, alloc, map);
  27123. list_for_each_entry(page, &n->full, lru)
  27124. process_slab(&t, s, page, alloc, map);
  27125. - spin_unlock_irqrestore(&n->list_lock, flags);
  27126. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  27127. }
  27128. for (i = 0; i < t.count; i++) {
  27129. diff -Nur linux-4.4.13.orig/mm/swap.c linux-4.4.13/mm/swap.c
  27130. --- linux-4.4.13.orig/mm/swap.c 2016-06-08 03:14:51.000000000 +0200
  27131. +++ linux-4.4.13/mm/swap.c 2016-06-22 21:55:08.078523867 +0200
  27132. @@ -31,6 +31,7 @@
  27133. #include <linux/memcontrol.h>
  27134. #include <linux/gfp.h>
  27135. #include <linux/uio.h>
  27136. +#include <linux/locallock.h>
  27137. #include <linux/hugetlb.h>
  27138. #include <linux/page_idle.h>
  27139. @@ -46,6 +47,9 @@
  27140. static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
  27141. static DEFINE_PER_CPU(struct pagevec, lru_deactivate_file_pvecs);
  27142. +static DEFINE_LOCAL_IRQ_LOCK(rotate_lock);
  27143. +DEFINE_LOCAL_IRQ_LOCK(swapvec_lock);
  27144. +
  27145. /*
  27146. * This path almost never happens for VM activity - pages are normally
  27147. * freed via pagevecs. But it gets used by networking.
  27148. @@ -481,11 +485,11 @@
  27149. unsigned long flags;
  27150. page_cache_get(page);
  27151. - local_irq_save(flags);
  27152. + local_lock_irqsave(rotate_lock, flags);
  27153. pvec = this_cpu_ptr(&lru_rotate_pvecs);
  27154. if (!pagevec_add(pvec, page))
  27155. pagevec_move_tail(pvec);
  27156. - local_irq_restore(flags);
  27157. + local_unlock_irqrestore(rotate_lock, flags);
  27158. }
  27159. }
  27160. @@ -536,12 +540,13 @@
  27161. void activate_page(struct page *page)
  27162. {
  27163. if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
  27164. - struct pagevec *pvec = &get_cpu_var(activate_page_pvecs);
  27165. + struct pagevec *pvec = &get_locked_var(swapvec_lock,
  27166. + activate_page_pvecs);
  27167. page_cache_get(page);
  27168. if (!pagevec_add(pvec, page))
  27169. pagevec_lru_move_fn(pvec, __activate_page, NULL);
  27170. - put_cpu_var(activate_page_pvecs);
  27171. + put_locked_var(swapvec_lock, activate_page_pvecs);
  27172. }
  27173. }
  27174. @@ -567,7 +572,7 @@
  27175. static void __lru_cache_activate_page(struct page *page)
  27176. {
  27177. - struct pagevec *pvec = &get_cpu_var(lru_add_pvec);
  27178. + struct pagevec *pvec = &get_locked_var(swapvec_lock, lru_add_pvec);
  27179. int i;
  27180. /*
  27181. @@ -589,7 +594,7 @@
  27182. }
  27183. }
  27184. - put_cpu_var(lru_add_pvec);
  27185. + put_locked_var(swapvec_lock, lru_add_pvec);
  27186. }
  27187. /*
  27188. @@ -630,13 +635,13 @@
  27189. static void __lru_cache_add(struct page *page)
  27190. {
  27191. - struct pagevec *pvec = &get_cpu_var(lru_add_pvec);
  27192. + struct pagevec *pvec = &get_locked_var(swapvec_lock, lru_add_pvec);
  27193. page_cache_get(page);
  27194. if (!pagevec_space(pvec))
  27195. __pagevec_lru_add(pvec);
  27196. pagevec_add(pvec, page);
  27197. - put_cpu_var(lru_add_pvec);
  27198. + put_locked_var(swapvec_lock, lru_add_pvec);
  27199. }
  27200. /**
  27201. @@ -816,9 +821,9 @@
  27202. unsigned long flags;
  27203. /* No harm done if a racing interrupt already did this */
  27204. - local_irq_save(flags);
  27205. + local_lock_irqsave(rotate_lock, flags);
  27206. pagevec_move_tail(pvec);
  27207. - local_irq_restore(flags);
  27208. + local_unlock_irqrestore(rotate_lock, flags);
  27209. }
  27210. pvec = &per_cpu(lru_deactivate_file_pvecs, cpu);
  27211. @@ -846,18 +851,19 @@
  27212. return;
  27213. if (likely(get_page_unless_zero(page))) {
  27214. - struct pagevec *pvec = &get_cpu_var(lru_deactivate_file_pvecs);
  27215. + struct pagevec *pvec = &get_locked_var(swapvec_lock,
  27216. + lru_deactivate_file_pvecs);
  27217. if (!pagevec_add(pvec, page))
  27218. pagevec_lru_move_fn(pvec, lru_deactivate_file_fn, NULL);
  27219. - put_cpu_var(lru_deactivate_file_pvecs);
  27220. + put_locked_var(swapvec_lock, lru_deactivate_file_pvecs);
  27221. }
  27222. }
  27223. void lru_add_drain(void)
  27224. {
  27225. - lru_add_drain_cpu(get_cpu());
  27226. - put_cpu();
  27227. + lru_add_drain_cpu(local_lock_cpu(swapvec_lock));
  27228. + local_unlock_cpu(swapvec_lock);
  27229. }
  27230. static void lru_add_drain_per_cpu(struct work_struct *dummy)
  27231. diff -Nur linux-4.4.13.orig/mm/truncate.c linux-4.4.13/mm/truncate.c
  27232. --- linux-4.4.13.orig/mm/truncate.c 2016-06-08 03:14:51.000000000 +0200
  27233. +++ linux-4.4.13/mm/truncate.c 2016-06-22 21:55:08.078523867 +0200
  27234. @@ -56,8 +56,11 @@
  27235. * protected by mapping->tree_lock.
  27236. */
  27237. if (!workingset_node_shadows(node) &&
  27238. - !list_empty(&node->private_list))
  27239. - list_lru_del(&workingset_shadow_nodes, &node->private_list);
  27240. + !list_empty(&node->private_list)) {
  27241. + local_lock(workingset_shadow_lock);
  27242. + list_lru_del(&__workingset_shadow_nodes, &node->private_list);
  27243. + local_unlock(workingset_shadow_lock);
  27244. + }
  27245. __radix_tree_delete_node(&mapping->page_tree, node);
  27246. unlock:
  27247. spin_unlock_irq(&mapping->tree_lock);
  27248. diff -Nur linux-4.4.13.orig/mm/vmalloc.c linux-4.4.13/mm/vmalloc.c
  27249. --- linux-4.4.13.orig/mm/vmalloc.c 2016-06-08 03:14:51.000000000 +0200
  27250. +++ linux-4.4.13/mm/vmalloc.c 2016-06-22 21:55:08.078523867 +0200
  27251. @@ -821,7 +821,7 @@
  27252. struct vmap_block *vb;
  27253. struct vmap_area *va;
  27254. unsigned long vb_idx;
  27255. - int node, err;
  27256. + int node, err, cpu;
  27257. void *vaddr;
  27258. node = numa_node_id();
  27259. @@ -864,11 +864,12 @@
  27260. BUG_ON(err);
  27261. radix_tree_preload_end();
  27262. - vbq = &get_cpu_var(vmap_block_queue);
  27263. + cpu = get_cpu_light();
  27264. + vbq = this_cpu_ptr(&vmap_block_queue);
  27265. spin_lock(&vbq->lock);
  27266. list_add_tail_rcu(&vb->free_list, &vbq->free);
  27267. spin_unlock(&vbq->lock);
  27268. - put_cpu_var(vmap_block_queue);
  27269. + put_cpu_light();
  27270. return vaddr;
  27271. }
  27272. @@ -937,6 +938,7 @@
  27273. struct vmap_block *vb;
  27274. void *vaddr = NULL;
  27275. unsigned int order;
  27276. + int cpu;
  27277. BUG_ON(offset_in_page(size));
  27278. BUG_ON(size > PAGE_SIZE*VMAP_MAX_ALLOC);
  27279. @@ -951,7 +953,8 @@
  27280. order = get_order(size);
  27281. rcu_read_lock();
  27282. - vbq = &get_cpu_var(vmap_block_queue);
  27283. + cpu = get_cpu_light();
  27284. + vbq = this_cpu_ptr(&vmap_block_queue);
  27285. list_for_each_entry_rcu(vb, &vbq->free, free_list) {
  27286. unsigned long pages_off;
  27287. @@ -974,7 +977,7 @@
  27288. break;
  27289. }
  27290. - put_cpu_var(vmap_block_queue);
  27291. + put_cpu_light();
  27292. rcu_read_unlock();
  27293. /* Allocate new block if nothing was found */
  27294. diff -Nur linux-4.4.13.orig/mm/vmstat.c linux-4.4.13/mm/vmstat.c
  27295. --- linux-4.4.13.orig/mm/vmstat.c 2016-06-08 03:14:51.000000000 +0200
  27296. +++ linux-4.4.13/mm/vmstat.c 2016-06-22 21:55:08.078523867 +0200
  27297. @@ -226,6 +226,7 @@
  27298. long x;
  27299. long t;
  27300. + preempt_disable_rt();
  27301. x = delta + __this_cpu_read(*p);
  27302. t = __this_cpu_read(pcp->stat_threshold);
  27303. @@ -235,6 +236,7 @@
  27304. x = 0;
  27305. }
  27306. __this_cpu_write(*p, x);
  27307. + preempt_enable_rt();
  27308. }
  27309. EXPORT_SYMBOL(__mod_zone_page_state);
  27310. @@ -267,6 +269,7 @@
  27311. s8 __percpu *p = pcp->vm_stat_diff + item;
  27312. s8 v, t;
  27313. + preempt_disable_rt();
  27314. v = __this_cpu_inc_return(*p);
  27315. t = __this_cpu_read(pcp->stat_threshold);
  27316. if (unlikely(v > t)) {
  27317. @@ -275,6 +278,7 @@
  27318. zone_page_state_add(v + overstep, zone, item);
  27319. __this_cpu_write(*p, -overstep);
  27320. }
  27321. + preempt_enable_rt();
  27322. }
  27323. void __inc_zone_page_state(struct page *page, enum zone_stat_item item)
  27324. @@ -289,6 +293,7 @@
  27325. s8 __percpu *p = pcp->vm_stat_diff + item;
  27326. s8 v, t;
  27327. + preempt_disable_rt();
  27328. v = __this_cpu_dec_return(*p);
  27329. t = __this_cpu_read(pcp->stat_threshold);
  27330. if (unlikely(v < - t)) {
  27331. @@ -297,6 +302,7 @@
  27332. zone_page_state_add(v - overstep, zone, item);
  27333. __this_cpu_write(*p, overstep);
  27334. }
  27335. + preempt_enable_rt();
  27336. }
  27337. void __dec_zone_page_state(struct page *page, enum zone_stat_item item)
  27338. diff -Nur linux-4.4.13.orig/mm/workingset.c linux-4.4.13/mm/workingset.c
  27339. --- linux-4.4.13.orig/mm/workingset.c 2016-06-08 03:14:51.000000000 +0200
  27340. +++ linux-4.4.13/mm/workingset.c 2016-06-22 21:55:08.078523867 +0200
  27341. @@ -264,7 +264,8 @@
  27342. * point where they would still be useful.
  27343. */
  27344. -struct list_lru workingset_shadow_nodes;
  27345. +struct list_lru __workingset_shadow_nodes;
  27346. +DEFINE_LOCAL_IRQ_LOCK(workingset_shadow_lock);
  27347. static unsigned long count_shadow_nodes(struct shrinker *shrinker,
  27348. struct shrink_control *sc)
  27349. @@ -274,9 +275,9 @@
  27350. unsigned long pages;
  27351. /* list_lru lock nests inside IRQ-safe mapping->tree_lock */
  27352. - local_irq_disable();
  27353. - shadow_nodes = list_lru_shrink_count(&workingset_shadow_nodes, sc);
  27354. - local_irq_enable();
  27355. + local_lock_irq(workingset_shadow_lock);
  27356. + shadow_nodes = list_lru_shrink_count(&__workingset_shadow_nodes, sc);
  27357. + local_unlock_irq(workingset_shadow_lock);
  27358. pages = node_present_pages(sc->nid);
  27359. /*
  27360. @@ -363,9 +364,9 @@
  27361. spin_unlock(&mapping->tree_lock);
  27362. ret = LRU_REMOVED_RETRY;
  27363. out:
  27364. - local_irq_enable();
  27365. + local_unlock_irq(workingset_shadow_lock);
  27366. cond_resched();
  27367. - local_irq_disable();
  27368. + local_lock_irq(workingset_shadow_lock);
  27369. spin_lock(lru_lock);
  27370. return ret;
  27371. }
  27372. @@ -376,10 +377,10 @@
  27373. unsigned long ret;
  27374. /* list_lru lock nests inside IRQ-safe mapping->tree_lock */
  27375. - local_irq_disable();
  27376. - ret = list_lru_shrink_walk(&workingset_shadow_nodes, sc,
  27377. + local_lock_irq(workingset_shadow_lock);
  27378. + ret = list_lru_shrink_walk(&__workingset_shadow_nodes, sc,
  27379. shadow_lru_isolate, NULL);
  27380. - local_irq_enable();
  27381. + local_unlock_irq(workingset_shadow_lock);
  27382. return ret;
  27383. }
  27384. @@ -400,7 +401,7 @@
  27385. {
  27386. int ret;
  27387. - ret = list_lru_init_key(&workingset_shadow_nodes, &shadow_nodes_key);
  27388. + ret = list_lru_init_key(&__workingset_shadow_nodes, &shadow_nodes_key);
  27389. if (ret)
  27390. goto err;
  27391. ret = register_shrinker(&workingset_shadow_shrinker);
  27392. @@ -408,7 +409,7 @@
  27393. goto err_list_lru;
  27394. return 0;
  27395. err_list_lru:
  27396. - list_lru_destroy(&workingset_shadow_nodes);
  27397. + list_lru_destroy(&__workingset_shadow_nodes);
  27398. err:
  27399. return ret;
  27400. }
  27401. diff -Nur linux-4.4.13.orig/mm/zsmalloc.c linux-4.4.13/mm/zsmalloc.c
  27402. --- linux-4.4.13.orig/mm/zsmalloc.c 2016-06-08 03:14:51.000000000 +0200
  27403. +++ linux-4.4.13/mm/zsmalloc.c 2016-06-22 21:55:08.078523867 +0200
  27404. @@ -1289,7 +1289,7 @@
  27405. class = pool->size_class[class_idx];
  27406. off = obj_idx_to_offset(page, obj_idx, class->size);
  27407. - area = &get_cpu_var(zs_map_area);
  27408. + area = per_cpu_ptr(&zs_map_area, get_cpu_light());
  27409. area->vm_mm = mm;
  27410. if (off + class->size <= PAGE_SIZE) {
  27411. /* this object is contained entirely within a page */
  27412. @@ -1342,7 +1342,7 @@
  27413. __zs_unmap_object(area, pages, off, class->size);
  27414. }
  27415. - put_cpu_var(zs_map_area);
  27416. + put_cpu_light();
  27417. unpin_tag(handle);
  27418. }
  27419. EXPORT_SYMBOL_GPL(zs_unmap_object);
  27420. diff -Nur linux-4.4.13.orig/net/core/dev.c linux-4.4.13/net/core/dev.c
  27421. --- linux-4.4.13.orig/net/core/dev.c 2016-06-08 03:14:51.000000000 +0200
  27422. +++ linux-4.4.13/net/core/dev.c 2016-06-22 21:55:08.082523867 +0200
  27423. @@ -186,6 +186,7 @@
  27424. static DEFINE_HASHTABLE(napi_hash, 8);
  27425. static seqcount_t devnet_rename_seq;
  27426. +static DEFINE_MUTEX(devnet_rename_mutex);
  27427. static inline void dev_base_seq_inc(struct net *net)
  27428. {
  27429. @@ -207,14 +208,14 @@
  27430. static inline void rps_lock(struct softnet_data *sd)
  27431. {
  27432. #ifdef CONFIG_RPS
  27433. - spin_lock(&sd->input_pkt_queue.lock);
  27434. + raw_spin_lock(&sd->input_pkt_queue.raw_lock);
  27435. #endif
  27436. }
  27437. static inline void rps_unlock(struct softnet_data *sd)
  27438. {
  27439. #ifdef CONFIG_RPS
  27440. - spin_unlock(&sd->input_pkt_queue.lock);
  27441. + raw_spin_unlock(&sd->input_pkt_queue.raw_lock);
  27442. #endif
  27443. }
  27444. @@ -884,7 +885,8 @@
  27445. strcpy(name, dev->name);
  27446. rcu_read_unlock();
  27447. if (read_seqcount_retry(&devnet_rename_seq, seq)) {
  27448. - cond_resched();
  27449. + mutex_lock(&devnet_rename_mutex);
  27450. + mutex_unlock(&devnet_rename_mutex);
  27451. goto retry;
  27452. }
  27453. @@ -1153,20 +1155,17 @@
  27454. if (dev->flags & IFF_UP)
  27455. return -EBUSY;
  27456. - write_seqcount_begin(&devnet_rename_seq);
  27457. + mutex_lock(&devnet_rename_mutex);
  27458. + __raw_write_seqcount_begin(&devnet_rename_seq);
  27459. - if (strncmp(newname, dev->name, IFNAMSIZ) == 0) {
  27460. - write_seqcount_end(&devnet_rename_seq);
  27461. - return 0;
  27462. - }
  27463. + if (strncmp(newname, dev->name, IFNAMSIZ) == 0)
  27464. + goto outunlock;
  27465. memcpy(oldname, dev->name, IFNAMSIZ);
  27466. err = dev_get_valid_name(net, dev, newname);
  27467. - if (err < 0) {
  27468. - write_seqcount_end(&devnet_rename_seq);
  27469. - return err;
  27470. - }
  27471. + if (err < 0)
  27472. + goto outunlock;
  27473. if (oldname[0] && !strchr(oldname, '%'))
  27474. netdev_info(dev, "renamed from %s\n", oldname);
  27475. @@ -1179,11 +1178,12 @@
  27476. if (ret) {
  27477. memcpy(dev->name, oldname, IFNAMSIZ);
  27478. dev->name_assign_type = old_assign_type;
  27479. - write_seqcount_end(&devnet_rename_seq);
  27480. - return ret;
  27481. + err = ret;
  27482. + goto outunlock;
  27483. }
  27484. - write_seqcount_end(&devnet_rename_seq);
  27485. + __raw_write_seqcount_end(&devnet_rename_seq);
  27486. + mutex_unlock(&devnet_rename_mutex);
  27487. netdev_adjacent_rename_links(dev, oldname);
  27488. @@ -1204,7 +1204,8 @@
  27489. /* err >= 0 after dev_alloc_name() or stores the first errno */
  27490. if (err >= 0) {
  27491. err = ret;
  27492. - write_seqcount_begin(&devnet_rename_seq);
  27493. + mutex_lock(&devnet_rename_mutex);
  27494. + __raw_write_seqcount_begin(&devnet_rename_seq);
  27495. memcpy(dev->name, oldname, IFNAMSIZ);
  27496. memcpy(oldname, newname, IFNAMSIZ);
  27497. dev->name_assign_type = old_assign_type;
  27498. @@ -1217,6 +1218,11 @@
  27499. }
  27500. return err;
  27501. +
  27502. +outunlock:
  27503. + __raw_write_seqcount_end(&devnet_rename_seq);
  27504. + mutex_unlock(&devnet_rename_mutex);
  27505. + return err;
  27506. }
  27507. /**
  27508. @@ -2246,6 +2252,7 @@
  27509. sd->output_queue_tailp = &q->next_sched;
  27510. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  27511. local_irq_restore(flags);
  27512. + preempt_check_resched_rt();
  27513. }
  27514. void __netif_schedule(struct Qdisc *q)
  27515. @@ -2327,6 +2334,7 @@
  27516. __this_cpu_write(softnet_data.completion_queue, skb);
  27517. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  27518. local_irq_restore(flags);
  27519. + preempt_check_resched_rt();
  27520. }
  27521. EXPORT_SYMBOL(__dev_kfree_skb_irq);
  27522. @@ -2883,7 +2891,11 @@
  27523. * This permits __QDISC___STATE_RUNNING owner to get the lock more
  27524. * often and dequeue packets faster.
  27525. */
  27526. +#ifdef CONFIG_PREEMPT_RT_FULL
  27527. + contended = true;
  27528. +#else
  27529. contended = qdisc_is_running(q);
  27530. +#endif
  27531. if (unlikely(contended))
  27532. spin_lock(&q->busylock);
  27533. @@ -2943,9 +2955,44 @@
  27534. #define skb_update_prio(skb)
  27535. #endif
  27536. +#ifdef CONFIG_PREEMPT_RT_FULL
  27537. +
  27538. +static inline int xmit_rec_read(void)
  27539. +{
  27540. + return current->xmit_recursion;
  27541. +}
  27542. +
  27543. +static inline void xmit_rec_inc(void)
  27544. +{
  27545. + current->xmit_recursion++;
  27546. +}
  27547. +
  27548. +static inline void xmit_rec_dec(void)
  27549. +{
  27550. + current->xmit_recursion--;
  27551. +}
  27552. +
  27553. +#else
  27554. +
  27555. DEFINE_PER_CPU(int, xmit_recursion);
  27556. EXPORT_SYMBOL(xmit_recursion);
  27557. +static inline int xmit_rec_read(void)
  27558. +{
  27559. + return __this_cpu_read(xmit_recursion);
  27560. +}
  27561. +
  27562. +static inline void xmit_rec_inc(void)
  27563. +{
  27564. + __this_cpu_inc(xmit_recursion);
  27565. +}
  27566. +
  27567. +static inline void xmit_rec_dec(void)
  27568. +{
  27569. + __this_cpu_dec(xmit_recursion);
  27570. +}
  27571. +#endif
  27572. +
  27573. #define RECURSION_LIMIT 10
  27574. /**
  27575. @@ -3138,7 +3185,7 @@
  27576. if (txq->xmit_lock_owner != cpu) {
  27577. - if (__this_cpu_read(xmit_recursion) > RECURSION_LIMIT)
  27578. + if (xmit_rec_read() > RECURSION_LIMIT)
  27579. goto recursion_alert;
  27580. skb = validate_xmit_skb(skb, dev);
  27581. @@ -3148,9 +3195,9 @@
  27582. HARD_TX_LOCK(dev, txq, cpu);
  27583. if (!netif_xmit_stopped(txq)) {
  27584. - __this_cpu_inc(xmit_recursion);
  27585. + xmit_rec_inc();
  27586. skb = dev_hard_start_xmit(skb, dev, txq, &rc);
  27587. - __this_cpu_dec(xmit_recursion);
  27588. + xmit_rec_dec();
  27589. if (dev_xmit_complete(rc)) {
  27590. HARD_TX_UNLOCK(dev, txq);
  27591. goto out;
  27592. @@ -3524,6 +3571,7 @@
  27593. rps_unlock(sd);
  27594. local_irq_restore(flags);
  27595. + preempt_check_resched_rt();
  27596. atomic_long_inc(&skb->dev->rx_dropped);
  27597. kfree_skb(skb);
  27598. @@ -3542,7 +3590,7 @@
  27599. struct rps_dev_flow voidflow, *rflow = &voidflow;
  27600. int cpu;
  27601. - preempt_disable();
  27602. + migrate_disable();
  27603. rcu_read_lock();
  27604. cpu = get_rps_cpu(skb->dev, skb, &rflow);
  27605. @@ -3552,13 +3600,13 @@
  27606. ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail);
  27607. rcu_read_unlock();
  27608. - preempt_enable();
  27609. + migrate_enable();
  27610. } else
  27611. #endif
  27612. {
  27613. unsigned int qtail;
  27614. - ret = enqueue_to_backlog(skb, get_cpu(), &qtail);
  27615. - put_cpu();
  27616. + ret = enqueue_to_backlog(skb, get_cpu_light(), &qtail);
  27617. + put_cpu_light();
  27618. }
  27619. return ret;
  27620. }
  27621. @@ -3592,16 +3640,44 @@
  27622. trace_netif_rx_ni_entry(skb);
  27623. - preempt_disable();
  27624. + local_bh_disable();
  27625. err = netif_rx_internal(skb);
  27626. - if (local_softirq_pending())
  27627. - do_softirq();
  27628. - preempt_enable();
  27629. + local_bh_enable();
  27630. return err;
  27631. }
  27632. EXPORT_SYMBOL(netif_rx_ni);
  27633. +#ifdef CONFIG_PREEMPT_RT_FULL
  27634. +/*
  27635. + * RT runs ksoftirqd as a real time thread and the root_lock is a
  27636. + * "sleeping spinlock". If the trylock fails then we can go into an
  27637. + * infinite loop when ksoftirqd preempted the task which actually
  27638. + * holds the lock, because we requeue q and raise NET_TX softirq
  27639. + * causing ksoftirqd to loop forever.
  27640. + *
  27641. + * It's safe to use spin_lock on RT here as softirqs run in thread
  27642. + * context and cannot deadlock against the thread which is holding
  27643. + * root_lock.
  27644. + *
  27645. + * On !RT the trylock might fail, but there we bail out from the
  27646. + * softirq loop after 10 attempts which we can't do on RT. And the
  27647. + * task holding root_lock cannot be preempted, so the only downside of
  27648. + * that trylock is that we need 10 loops to decide that we should have
  27649. + * given up in the first one :)
  27650. + */
  27651. +static inline int take_root_lock(spinlock_t *lock)
  27652. +{
  27653. + spin_lock(lock);
  27654. + return 1;
  27655. +}
  27656. +#else
  27657. +static inline int take_root_lock(spinlock_t *lock)
  27658. +{
  27659. + return spin_trylock(lock);
  27660. +}
  27661. +#endif
  27662. +
  27663. static void net_tx_action(struct softirq_action *h)
  27664. {
  27665. struct softnet_data *sd = this_cpu_ptr(&softnet_data);
  27666. @@ -3643,7 +3719,7 @@
  27667. head = head->next_sched;
  27668. root_lock = qdisc_lock(q);
  27669. - if (spin_trylock(root_lock)) {
  27670. + if (take_root_lock(root_lock)) {
  27671. smp_mb__before_atomic();
  27672. clear_bit(__QDISC_STATE_SCHED,
  27673. &q->state);
  27674. @@ -4049,7 +4125,7 @@
  27675. skb_queue_walk_safe(&sd->input_pkt_queue, skb, tmp) {
  27676. if (skb->dev == dev) {
  27677. __skb_unlink(skb, &sd->input_pkt_queue);
  27678. - kfree_skb(skb);
  27679. + __skb_queue_tail(&sd->tofree_queue, skb);
  27680. input_queue_head_incr(sd);
  27681. }
  27682. }
  27683. @@ -4058,10 +4134,13 @@
  27684. skb_queue_walk_safe(&sd->process_queue, skb, tmp) {
  27685. if (skb->dev == dev) {
  27686. __skb_unlink(skb, &sd->process_queue);
  27687. - kfree_skb(skb);
  27688. + __skb_queue_tail(&sd->tofree_queue, skb);
  27689. input_queue_head_incr(sd);
  27690. }
  27691. }
  27692. +
  27693. + if (!skb_queue_empty(&sd->tofree_queue))
  27694. + raise_softirq_irqoff(NET_RX_SOFTIRQ);
  27695. }
  27696. static int napi_gro_complete(struct sk_buff *skb)
  27697. @@ -4515,6 +4594,7 @@
  27698. sd->rps_ipi_list = NULL;
  27699. local_irq_enable();
  27700. + preempt_check_resched_rt();
  27701. /* Send pending IPI's to kick RPS processing on remote cpus. */
  27702. while (remsd) {
  27703. @@ -4528,6 +4608,7 @@
  27704. } else
  27705. #endif
  27706. local_irq_enable();
  27707. + preempt_check_resched_rt();
  27708. }
  27709. static bool sd_has_rps_ipi_waiting(struct softnet_data *sd)
  27710. @@ -4609,6 +4690,7 @@
  27711. local_irq_save(flags);
  27712. ____napi_schedule(this_cpu_ptr(&softnet_data), n);
  27713. local_irq_restore(flags);
  27714. + preempt_check_resched_rt();
  27715. }
  27716. EXPORT_SYMBOL(__napi_schedule);
  27717. @@ -4885,7 +4967,7 @@
  27718. list_splice_tail(&repoll, &list);
  27719. list_splice(&list, &sd->poll_list);
  27720. if (!list_empty(&sd->poll_list))
  27721. - __raise_softirq_irqoff(NET_RX_SOFTIRQ);
  27722. + __raise_softirq_irqoff_ksoft(NET_RX_SOFTIRQ);
  27723. net_rps_action_and_irq_enable(sd);
  27724. }
  27725. @@ -7218,7 +7300,7 @@
  27726. void synchronize_net(void)
  27727. {
  27728. might_sleep();
  27729. - if (rtnl_is_locked())
  27730. + if (rtnl_is_locked() && !IS_ENABLED(CONFIG_PREEMPT_RT_FULL))
  27731. synchronize_rcu_expedited();
  27732. else
  27733. synchronize_rcu();
  27734. @@ -7459,16 +7541,20 @@
  27735. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  27736. local_irq_enable();
  27737. + preempt_check_resched_rt();
  27738. /* Process offline CPU's input_pkt_queue */
  27739. while ((skb = __skb_dequeue(&oldsd->process_queue))) {
  27740. netif_rx_ni(skb);
  27741. input_queue_head_incr(oldsd);
  27742. }
  27743. - while ((skb = skb_dequeue(&oldsd->input_pkt_queue))) {
  27744. + while ((skb = __skb_dequeue(&oldsd->input_pkt_queue))) {
  27745. netif_rx_ni(skb);
  27746. input_queue_head_incr(oldsd);
  27747. }
  27748. + while ((skb = __skb_dequeue(&oldsd->tofree_queue))) {
  27749. + kfree_skb(skb);
  27750. + }
  27751. return NOTIFY_OK;
  27752. }
  27753. @@ -7770,8 +7856,9 @@
  27754. for_each_possible_cpu(i) {
  27755. struct softnet_data *sd = &per_cpu(softnet_data, i);
  27756. - skb_queue_head_init(&sd->input_pkt_queue);
  27757. - skb_queue_head_init(&sd->process_queue);
  27758. + skb_queue_head_init_raw(&sd->input_pkt_queue);
  27759. + skb_queue_head_init_raw(&sd->process_queue);
  27760. + skb_queue_head_init_raw(&sd->tofree_queue);
  27761. INIT_LIST_HEAD(&sd->poll_list);
  27762. sd->output_queue_tailp = &sd->output_queue;
  27763. #ifdef CONFIG_RPS
  27764. diff -Nur linux-4.4.13.orig/net/core/skbuff.c linux-4.4.13/net/core/skbuff.c
  27765. --- linux-4.4.13.orig/net/core/skbuff.c 2016-06-08 03:14:51.000000000 +0200
  27766. +++ linux-4.4.13/net/core/skbuff.c 2016-06-22 21:55:08.082523867 +0200
  27767. @@ -63,6 +63,7 @@
  27768. #include <linux/errqueue.h>
  27769. #include <linux/prefetch.h>
  27770. #include <linux/if_vlan.h>
  27771. +#include <linux/locallock.h>
  27772. #include <net/protocol.h>
  27773. #include <net/dst.h>
  27774. @@ -351,6 +352,8 @@
  27775. static DEFINE_PER_CPU(struct page_frag_cache, netdev_alloc_cache);
  27776. static DEFINE_PER_CPU(struct page_frag_cache, napi_alloc_cache);
  27777. +static DEFINE_LOCAL_IRQ_LOCK(netdev_alloc_lock);
  27778. +static DEFINE_LOCAL_IRQ_LOCK(napi_alloc_cache_lock);
  27779. static void *__netdev_alloc_frag(unsigned int fragsz, gfp_t gfp_mask)
  27780. {
  27781. @@ -358,10 +361,10 @@
  27782. unsigned long flags;
  27783. void *data;
  27784. - local_irq_save(flags);
  27785. + local_lock_irqsave(netdev_alloc_lock, flags);
  27786. nc = this_cpu_ptr(&netdev_alloc_cache);
  27787. data = __alloc_page_frag(nc, fragsz, gfp_mask);
  27788. - local_irq_restore(flags);
  27789. + local_unlock_irqrestore(netdev_alloc_lock, flags);
  27790. return data;
  27791. }
  27792. @@ -380,9 +383,13 @@
  27793. static void *__napi_alloc_frag(unsigned int fragsz, gfp_t gfp_mask)
  27794. {
  27795. - struct page_frag_cache *nc = this_cpu_ptr(&napi_alloc_cache);
  27796. + struct page_frag_cache *nc;
  27797. + void *data;
  27798. - return __alloc_page_frag(nc, fragsz, gfp_mask);
  27799. + nc = &get_locked_var(napi_alloc_cache_lock, napi_alloc_cache);
  27800. + data = __alloc_page_frag(nc, fragsz, gfp_mask);
  27801. + put_locked_var(napi_alloc_cache_lock, napi_alloc_cache);
  27802. + return data;
  27803. }
  27804. void *napi_alloc_frag(unsigned int fragsz)
  27805. @@ -429,13 +436,13 @@
  27806. if (sk_memalloc_socks())
  27807. gfp_mask |= __GFP_MEMALLOC;
  27808. - local_irq_save(flags);
  27809. + local_lock_irqsave(netdev_alloc_lock, flags);
  27810. nc = this_cpu_ptr(&netdev_alloc_cache);
  27811. data = __alloc_page_frag(nc, len, gfp_mask);
  27812. pfmemalloc = nc->pfmemalloc;
  27813. - local_irq_restore(flags);
  27814. + local_unlock_irqrestore(netdev_alloc_lock, flags);
  27815. if (unlikely(!data))
  27816. return NULL;
  27817. @@ -476,9 +483,10 @@
  27818. struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
  27819. gfp_t gfp_mask)
  27820. {
  27821. - struct page_frag_cache *nc = this_cpu_ptr(&napi_alloc_cache);
  27822. + struct page_frag_cache *nc;
  27823. struct sk_buff *skb;
  27824. void *data;
  27825. + bool pfmemalloc;
  27826. len += NET_SKB_PAD + NET_IP_ALIGN;
  27827. @@ -496,7 +504,11 @@
  27828. if (sk_memalloc_socks())
  27829. gfp_mask |= __GFP_MEMALLOC;
  27830. + nc = &get_locked_var(napi_alloc_cache_lock, napi_alloc_cache);
  27831. data = __alloc_page_frag(nc, len, gfp_mask);
  27832. + pfmemalloc = nc->pfmemalloc;
  27833. + put_locked_var(napi_alloc_cache_lock, napi_alloc_cache);
  27834. +
  27835. if (unlikely(!data))
  27836. return NULL;
  27837. @@ -507,7 +519,7 @@
  27838. }
  27839. /* use OR instead of assignment to avoid clearing of bits in mask */
  27840. - if (nc->pfmemalloc)
  27841. + if (pfmemalloc)
  27842. skb->pfmemalloc = 1;
  27843. skb->head_frag = 1;
  27844. diff -Nur linux-4.4.13.orig/net/core/sock.c linux-4.4.13/net/core/sock.c
  27845. --- linux-4.4.13.orig/net/core/sock.c 2016-06-08 03:14:51.000000000 +0200
  27846. +++ linux-4.4.13/net/core/sock.c 2016-06-22 21:55:08.082523867 +0200
  27847. @@ -2435,12 +2435,11 @@
  27848. if (sk->sk_lock.owned)
  27849. __lock_sock(sk);
  27850. sk->sk_lock.owned = 1;
  27851. - spin_unlock(&sk->sk_lock.slock);
  27852. + spin_unlock_bh(&sk->sk_lock.slock);
  27853. /*
  27854. * The sk_lock has mutex_lock() semantics here:
  27855. */
  27856. mutex_acquire(&sk->sk_lock.dep_map, subclass, 0, _RET_IP_);
  27857. - local_bh_enable();
  27858. }
  27859. EXPORT_SYMBOL(lock_sock_nested);
  27860. diff -Nur linux-4.4.13.orig/net/ipv4/icmp.c linux-4.4.13/net/ipv4/icmp.c
  27861. --- linux-4.4.13.orig/net/ipv4/icmp.c 2016-06-08 03:14:51.000000000 +0200
  27862. +++ linux-4.4.13/net/ipv4/icmp.c 2016-06-22 21:55:08.082523867 +0200
  27863. @@ -69,6 +69,7 @@
  27864. #include <linux/jiffies.h>
  27865. #include <linux/kernel.h>
  27866. #include <linux/fcntl.h>
  27867. +#include <linux/sysrq.h>
  27868. #include <linux/socket.h>
  27869. #include <linux/in.h>
  27870. #include <linux/inet.h>
  27871. @@ -891,6 +892,30 @@
  27872. }
  27873. /*
  27874. + * 32bit and 64bit have different timestamp length, so we check for
  27875. + * the cookie at offset 20 and verify it is repeated at offset 50
  27876. + */
  27877. +#define CO_POS0 20
  27878. +#define CO_POS1 50
  27879. +#define CO_SIZE sizeof(int)
  27880. +#define ICMP_SYSRQ_SIZE 57
  27881. +
  27882. +/*
  27883. + * We got a ICMP_SYSRQ_SIZE sized ping request. Check for the cookie
  27884. + * pattern and if it matches send the next byte as a trigger to sysrq.
  27885. + */
  27886. +static void icmp_check_sysrq(struct net *net, struct sk_buff *skb)
  27887. +{
  27888. + int cookie = htonl(net->ipv4.sysctl_icmp_echo_sysrq);
  27889. + char *p = skb->data;
  27890. +
  27891. + if (!memcmp(&cookie, p + CO_POS0, CO_SIZE) &&
  27892. + !memcmp(&cookie, p + CO_POS1, CO_SIZE) &&
  27893. + p[CO_POS0 + CO_SIZE] == p[CO_POS1 + CO_SIZE])
  27894. + handle_sysrq(p[CO_POS0 + CO_SIZE]);
  27895. +}
  27896. +
  27897. +/*
  27898. * Handle ICMP_ECHO ("ping") requests.
  27899. *
  27900. * RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo
  27901. @@ -917,6 +942,11 @@
  27902. icmp_param.data_len = skb->len;
  27903. icmp_param.head_len = sizeof(struct icmphdr);
  27904. icmp_reply(&icmp_param, skb);
  27905. +
  27906. + if (skb->len == ICMP_SYSRQ_SIZE &&
  27907. + net->ipv4.sysctl_icmp_echo_sysrq) {
  27908. + icmp_check_sysrq(net, skb);
  27909. + }
  27910. }
  27911. /* should there be an ICMP stat for ignored echos? */
  27912. return true;
  27913. diff -Nur linux-4.4.13.orig/net/ipv4/sysctl_net_ipv4.c linux-4.4.13/net/ipv4/sysctl_net_ipv4.c
  27914. --- linux-4.4.13.orig/net/ipv4/sysctl_net_ipv4.c 2016-06-08 03:14:51.000000000 +0200
  27915. +++ linux-4.4.13/net/ipv4/sysctl_net_ipv4.c 2016-06-22 21:55:08.082523867 +0200
  27916. @@ -818,6 +818,13 @@
  27917. .proc_handler = proc_dointvec
  27918. },
  27919. {
  27920. + .procname = "icmp_echo_sysrq",
  27921. + .data = &init_net.ipv4.sysctl_icmp_echo_sysrq,
  27922. + .maxlen = sizeof(int),
  27923. + .mode = 0644,
  27924. + .proc_handler = proc_dointvec
  27925. + },
  27926. + {
  27927. .procname = "icmp_ignore_bogus_error_responses",
  27928. .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
  27929. .maxlen = sizeof(int),
  27930. diff -Nur linux-4.4.13.orig/net/mac80211/rx.c linux-4.4.13/net/mac80211/rx.c
  27931. --- linux-4.4.13.orig/net/mac80211/rx.c 2016-06-08 03:14:51.000000000 +0200
  27932. +++ linux-4.4.13/net/mac80211/rx.c 2016-06-22 21:55:08.082523867 +0200
  27933. @@ -3574,7 +3574,7 @@
  27934. struct ieee80211_supported_band *sband;
  27935. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  27936. - WARN_ON_ONCE(softirq_count() == 0);
  27937. + WARN_ON_ONCE_NONRT(softirq_count() == 0);
  27938. if (WARN_ON(status->band >= IEEE80211_NUM_BANDS))
  27939. goto drop;
  27940. diff -Nur linux-4.4.13.orig/net/netfilter/core.c linux-4.4.13/net/netfilter/core.c
  27941. --- linux-4.4.13.orig/net/netfilter/core.c 2016-06-08 03:14:51.000000000 +0200
  27942. +++ linux-4.4.13/net/netfilter/core.c 2016-06-22 21:55:08.082523867 +0200
  27943. @@ -22,11 +22,17 @@
  27944. #include <linux/proc_fs.h>
  27945. #include <linux/mutex.h>
  27946. #include <linux/slab.h>
  27947. +#include <linux/locallock.h>
  27948. #include <net/net_namespace.h>
  27949. #include <net/sock.h>
  27950. #include "nf_internals.h"
  27951. +#ifdef CONFIG_PREEMPT_RT_BASE
  27952. +DEFINE_LOCAL_IRQ_LOCK(xt_write_lock);
  27953. +EXPORT_PER_CPU_SYMBOL(xt_write_lock);
  27954. +#endif
  27955. +
  27956. static DEFINE_MUTEX(afinfo_mutex);
  27957. const struct nf_afinfo __rcu *nf_afinfo[NFPROTO_NUMPROTO] __read_mostly;
  27958. diff -Nur linux-4.4.13.orig/net/packet/af_packet.c linux-4.4.13/net/packet/af_packet.c
  27959. --- linux-4.4.13.orig/net/packet/af_packet.c 2016-06-08 03:14:51.000000000 +0200
  27960. +++ linux-4.4.13/net/packet/af_packet.c 2016-06-22 21:55:08.086523867 +0200
  27961. @@ -63,6 +63,7 @@
  27962. #include <linux/if_packet.h>
  27963. #include <linux/wireless.h>
  27964. #include <linux/kernel.h>
  27965. +#include <linux/delay.h>
  27966. #include <linux/kmod.h>
  27967. #include <linux/slab.h>
  27968. #include <linux/vmalloc.h>
  27969. @@ -695,7 +696,7 @@
  27970. if (BLOCK_NUM_PKTS(pbd)) {
  27971. while (atomic_read(&pkc->blk_fill_in_prog)) {
  27972. /* Waiting for skb_copy_bits to finish... */
  27973. - cpu_relax();
  27974. + cpu_chill();
  27975. }
  27976. }
  27977. @@ -957,7 +958,7 @@
  27978. if (!(status & TP_STATUS_BLK_TMO)) {
  27979. while (atomic_read(&pkc->blk_fill_in_prog)) {
  27980. /* Waiting for skb_copy_bits to finish... */
  27981. - cpu_relax();
  27982. + cpu_chill();
  27983. }
  27984. }
  27985. prb_close_block(pkc, pbd, po, status);
  27986. diff -Nur linux-4.4.13.orig/net/rds/ib_rdma.c linux-4.4.13/net/rds/ib_rdma.c
  27987. --- linux-4.4.13.orig/net/rds/ib_rdma.c 2016-06-08 03:14:51.000000000 +0200
  27988. +++ linux-4.4.13/net/rds/ib_rdma.c 2016-06-22 21:55:08.086523867 +0200
  27989. @@ -34,6 +34,7 @@
  27990. #include <linux/slab.h>
  27991. #include <linux/rculist.h>
  27992. #include <linux/llist.h>
  27993. +#include <linux/delay.h>
  27994. #include "rds.h"
  27995. #include "ib.h"
  27996. @@ -313,7 +314,7 @@
  27997. for_each_online_cpu(cpu) {
  27998. flag = &per_cpu(clean_list_grace, cpu);
  27999. while (test_bit(CLEAN_LIST_BUSY_BIT, flag))
  28000. - cpu_relax();
  28001. + cpu_chill();
  28002. }
  28003. }
  28004. diff -Nur linux-4.4.13.orig/net/sched/sch_generic.c linux-4.4.13/net/sched/sch_generic.c
  28005. --- linux-4.4.13.orig/net/sched/sch_generic.c 2016-06-08 03:14:51.000000000 +0200
  28006. +++ linux-4.4.13/net/sched/sch_generic.c 2016-06-22 21:55:08.086523867 +0200
  28007. @@ -893,7 +893,7 @@
  28008. /* Wait for outstanding qdisc_run calls. */
  28009. list_for_each_entry(dev, head, close_list)
  28010. while (some_qdisc_is_busy(dev))
  28011. - yield();
  28012. + msleep(1);
  28013. }
  28014. void dev_deactivate(struct net_device *dev)
  28015. diff -Nur linux-4.4.13.orig/net/sunrpc/svc_xprt.c linux-4.4.13/net/sunrpc/svc_xprt.c
  28016. --- linux-4.4.13.orig/net/sunrpc/svc_xprt.c 2016-06-08 03:14:51.000000000 +0200
  28017. +++ linux-4.4.13/net/sunrpc/svc_xprt.c 2016-06-22 21:55:08.086523867 +0200
  28018. @@ -340,7 +340,7 @@
  28019. goto out;
  28020. }
  28021. - cpu = get_cpu();
  28022. + cpu = get_cpu_light();
  28023. pool = svc_pool_for_cpu(xprt->xpt_server, cpu);
  28024. atomic_long_inc(&pool->sp_stats.packets);
  28025. @@ -376,7 +376,7 @@
  28026. atomic_long_inc(&pool->sp_stats.threads_woken);
  28027. wake_up_process(rqstp->rq_task);
  28028. - put_cpu();
  28029. + put_cpu_light();
  28030. goto out;
  28031. }
  28032. rcu_read_unlock();
  28033. @@ -397,7 +397,7 @@
  28034. goto redo_search;
  28035. }
  28036. rqstp = NULL;
  28037. - put_cpu();
  28038. + put_cpu_light();
  28039. out:
  28040. trace_svc_xprt_do_enqueue(xprt, rqstp);
  28041. }
  28042. diff -Nur linux-4.4.13.orig/scripts/mkcompile_h linux-4.4.13/scripts/mkcompile_h
  28043. --- linux-4.4.13.orig/scripts/mkcompile_h 2016-06-08 03:14:51.000000000 +0200
  28044. +++ linux-4.4.13/scripts/mkcompile_h 2016-06-22 21:55:08.086523867 +0200
  28045. @@ -4,7 +4,8 @@
  28046. ARCH=$2
  28047. SMP=$3
  28048. PREEMPT=$4
  28049. -CC=$5
  28050. +RT=$5
  28051. +CC=$6
  28052. vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }
  28053. @@ -57,6 +58,7 @@
  28054. CONFIG_FLAGS=""
  28055. if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
  28056. if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
  28057. +if [ -n "$RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS RT"; fi
  28058. UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP"
  28059. # Truncate to maximum length
  28060. diff -Nur linux-4.4.13.orig/sound/core/pcm_native.c linux-4.4.13/sound/core/pcm_native.c
  28061. --- linux-4.4.13.orig/sound/core/pcm_native.c 2016-06-08 03:14:51.000000000 +0200
  28062. +++ linux-4.4.13/sound/core/pcm_native.c 2016-06-22 21:55:08.086523867 +0200
  28063. @@ -135,7 +135,7 @@
  28064. void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
  28065. {
  28066. if (!substream->pcm->nonatomic)
  28067. - local_irq_disable();
  28068. + local_irq_disable_nort();
  28069. snd_pcm_stream_lock(substream);
  28070. }
  28071. EXPORT_SYMBOL_GPL(snd_pcm_stream_lock_irq);
  28072. @@ -150,7 +150,7 @@
  28073. {
  28074. snd_pcm_stream_unlock(substream);
  28075. if (!substream->pcm->nonatomic)
  28076. - local_irq_enable();
  28077. + local_irq_enable_nort();
  28078. }
  28079. EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irq);
  28080. @@ -158,7 +158,7 @@
  28081. {
  28082. unsigned long flags = 0;
  28083. if (!substream->pcm->nonatomic)
  28084. - local_irq_save(flags);
  28085. + local_irq_save_nort(flags);
  28086. snd_pcm_stream_lock(substream);
  28087. return flags;
  28088. }
  28089. @@ -176,7 +176,7 @@
  28090. {
  28091. snd_pcm_stream_unlock(substream);
  28092. if (!substream->pcm->nonatomic)
  28093. - local_irq_restore(flags);
  28094. + local_irq_restore_nort(flags);
  28095. }
  28096. EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irqrestore);
  28097. diff -Nur linux-4.4.13.orig/virt/kvm/async_pf.c linux-4.4.13/virt/kvm/async_pf.c
  28098. --- linux-4.4.13.orig/virt/kvm/async_pf.c 2016-06-08 03:14:51.000000000 +0200
  28099. +++ linux-4.4.13/virt/kvm/async_pf.c 2016-06-22 21:55:08.086523867 +0200
  28100. @@ -98,8 +98,8 @@
  28101. * This memory barrier pairs with prepare_to_wait's set_current_state()
  28102. */
  28103. smp_mb();
  28104. - if (waitqueue_active(&vcpu->wq))
  28105. - wake_up_interruptible(&vcpu->wq);
  28106. + if (swait_active(&vcpu->wq))
  28107. + swake_up(&vcpu->wq);
  28108. mmput(mm);
  28109. kvm_put_kvm(vcpu->kvm);
  28110. diff -Nur linux-4.4.13.orig/virt/kvm/kvm_main.c linux-4.4.13/virt/kvm/kvm_main.c
  28111. --- linux-4.4.13.orig/virt/kvm/kvm_main.c 2016-06-08 03:14:51.000000000 +0200
  28112. +++ linux-4.4.13/virt/kvm/kvm_main.c 2016-06-22 21:55:08.086523867 +0200
  28113. @@ -226,8 +226,7 @@
  28114. vcpu->kvm = kvm;
  28115. vcpu->vcpu_id = id;
  28116. vcpu->pid = NULL;
  28117. - vcpu->halt_poll_ns = 0;
  28118. - init_waitqueue_head(&vcpu->wq);
  28119. + init_swait_queue_head(&vcpu->wq);
  28120. kvm_async_pf_vcpu_init(vcpu);
  28121. vcpu->pre_pcpu = -1;
  28122. @@ -2003,7 +2002,7 @@
  28123. void kvm_vcpu_block(struct kvm_vcpu *vcpu)
  28124. {
  28125. ktime_t start, cur;
  28126. - DEFINE_WAIT(wait);
  28127. + DECLARE_SWAITQUEUE(wait);
  28128. bool waited = false;
  28129. u64 block_ns;
  28130. @@ -2028,7 +2027,7 @@
  28131. kvm_arch_vcpu_blocking(vcpu);
  28132. for (;;) {
  28133. - prepare_to_wait(&vcpu->wq, &wait, TASK_INTERRUPTIBLE);
  28134. + prepare_to_swait(&vcpu->wq, &wait, TASK_INTERRUPTIBLE);
  28135. if (kvm_vcpu_check_block(vcpu) < 0)
  28136. break;
  28137. @@ -2037,7 +2036,7 @@
  28138. schedule();
  28139. }
  28140. - finish_wait(&vcpu->wq, &wait);
  28141. + finish_swait(&vcpu->wq, &wait);
  28142. cur = ktime_get();
  28143. kvm_arch_vcpu_unblocking(vcpu);
  28144. @@ -2069,11 +2068,11 @@
  28145. {
  28146. int me;
  28147. int cpu = vcpu->cpu;
  28148. - wait_queue_head_t *wqp;
  28149. + struct swait_queue_head *wqp;
  28150. wqp = kvm_arch_vcpu_wq(vcpu);
  28151. - if (waitqueue_active(wqp)) {
  28152. - wake_up_interruptible(wqp);
  28153. + if (swait_active(wqp)) {
  28154. + swake_up(wqp);
  28155. ++vcpu->stat.halt_wakeup;
  28156. }
  28157. @@ -2174,7 +2173,7 @@
  28158. continue;
  28159. if (vcpu == me)
  28160. continue;
  28161. - if (waitqueue_active(&vcpu->wq) && !kvm_arch_vcpu_runnable(vcpu))
  28162. + if (swait_active(&vcpu->wq) && !kvm_arch_vcpu_runnable(vcpu))
  28163. continue;
  28164. if (!kvm_vcpu_eligible_for_directed_yield(vcpu))
  28165. continue;